Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to OOP: A Primer for Novice Developers

How to OOP: A Primer for Novice Developers

This talk is targeted at beginners that have the basics down but are unsure how to approach object-oriented programming. I'll be presenting 3 key ideas that they can go ahead and apply to their code immediately. Obviously I won't be able to cover everything I'd like to cover, but my hope is that they'll get a solid footing that they can build on.

Marco Petersen

May 08, 2018
Tweet

More Decks by Marco Petersen

Other Decks in Programming

Transcript

  1. How to OOP
    A Primer for Novice Developers

    View full-size slide

  2. Marco Petersen
    @ocrampete16

    View full-size slide

  3. ✗ an advanced OOP talk
    ✓ an intro to proper OOP

    View full-size slide

  4. Seasoned devs
    aren’t going to learn
    anything new.

    View full-size slide

  5. For people who know how
    classes work but don’t
    know how to use them
    effectively.

    View full-size slide

  6. Rich domain model
    Composition for code reuse
    Classes that focus on one thing

    View full-size slide

  7. Slides are on Speaker Deck at
    speakerdeck.com/ocrampete16

    View full-size slide

  8. Use classes to create a
    rich domain model.

    View full-size slide

  9. Your domain model is
    what your business is
    about.

    View full-size slide

  10. Model real-world
    behavior.

    View full-size slide

  11. Infrastructural
    concerns are irrelevant.

    View full-size slide

  12. Use classes to create a
    rich domain model.

    View full-size slide

  13. Composition for code
    reuse, not inheritance.

    View full-size slide

  14. Inheritance is for
    specialization, not for
    sharing logic.

    View full-size slide

  15. Is it a “more specific
    version” of this thing?

    View full-size slide

  16. Extract what’s different
    and “inject” it.
    (Dependency Injection)

    View full-size slide

  17. Dependency Injection
    !==
    Dependency Inversion

    View full-size slide

  18. Composition for code
    reuse, not inheritance.

    View full-size slide

  19. Smaller classes that
    only do one thing.

    View full-size slide

  20. Single Responsibility
    Principle (SOLID)

    View full-size slide

  21. What a “responsibility” is
    depends on the layer of
    abstraction you’re at.

    View full-size slide

  22. When is a class too big?
    Uncle Bob: more than one reason to
    change
    Uncle Marco: lots of dependencies

    View full-size slide

  23. Smaller classes that
    only do one thing.

    View full-size slide

  24. FINAL RECAP!

    View full-size slide

  25. Write classes that
    model the real world.

    View full-size slide

  26. Extract shared logic
    into their own classes
    and inject them.

    View full-size slide

  27. Classes should focus on
    doing one thing well.

    View full-size slide

  28. Thanks!
    Questions?

    View full-size slide