10 Top Tips for Good Object-Oriented Design

Preview:

DESCRIPTION

 

Citation preview

10 TOP TIPSfor good object-oriented design

WHO AM I?

• Founder of Cambridge Software Craftsmanship Community

• Developer and Technical Lead at Red Gate Software

• Twitter: @alastairs

• http://www.codebork.com/

• alastair@alastairsmith.me.uk

1. OBJECT-ORIENTATION MESSAGE-ORIENTATION

• Values are passed between objects as messages

• Tell objects, ask values• “Don’t call us, we’ll call you”

• State is only there to support behaviour

2. FAVOUR COMPOSITION OVER INHERITANCE

• Loose coupling

• Strategies, Adapters, Composites and more are your friends

3. THERE IS A CONTINUUM OF ABSTRACTION

Instance

Class

Abstract Class

Interface

4. USE ABSTRACT CLASSES

• Not every abstract concept should be an interface

• Model all your abstractions at the right level

5. DON’T EXPOSE STATE ON INTERFACES

• Interfaces are contracts of behaviour

• State is data

6. PROGRAM TO THE INTERFACE, NOT THE IMPLEMENTATION

• Loose coupling

• Assume nothing about the implementation of the interface

7. INHERITANCE IS FOR SPECIALISATION

• Use composition for extension

• Specialisation is like evolution

8. KNOW YOUR PATTERNS

• Design Patterns are our bricks and mortar

• Use GoF as a reference only

9. AT THE BOUNDARIES OF AN APPLICATION, OO BREAKS DOWN

• Use value objects to convey state out of the core of the application

• Do not reuse abstractions in different modules

• Use hexagonal architecture to separate concerns

10. MAKE YOUR OBJECTS AND VALUES IMMUTABLE

• Easier comparisons when testing• Both have a concept of equality

• Thread safety in multi-threaded systems

• Less complex implementation

ANY QUESTIONS?Thank you for listening!

Recommended