13
10 TOP TIPS for good object-oriented design

10 Top Tips for Good Object-Oriented Design

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: 10 Top Tips for Good Object-Oriented Design

10 TOP TIPSfor good object-oriented design

Page 2: 10 Top Tips for 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/

[email protected]

Page 3: 10 Top Tips for Good Object-Oriented Design

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

Page 4: 10 Top Tips for Good Object-Oriented Design

2. FAVOUR COMPOSITION OVER INHERITANCE

• Loose coupling

• Strategies, Adapters, Composites and more are your friends

Page 5: 10 Top Tips for Good Object-Oriented Design

3. THERE IS A CONTINUUM OF ABSTRACTION

Instance

Class

Abstract Class

Interface

Page 6: 10 Top Tips for Good Object-Oriented Design

4. USE ABSTRACT CLASSES

• Not every abstract concept should be an interface

• Model all your abstractions at the right level

Page 7: 10 Top Tips for Good Object-Oriented Design

5. DON’T EXPOSE STATE ON INTERFACES

• Interfaces are contracts of behaviour

• State is data

Page 8: 10 Top Tips for Good Object-Oriented Design

6. PROGRAM TO THE INTERFACE, NOT THE IMPLEMENTATION

• Loose coupling

• Assume nothing about the implementation of the interface

Page 9: 10 Top Tips for Good Object-Oriented Design

7. INHERITANCE IS FOR SPECIALISATION

• Use composition for extension

• Specialisation is like evolution

Page 10: 10 Top Tips for Good Object-Oriented Design

8. KNOW YOUR PATTERNS

• Design Patterns are our bricks and mortar

• Use GoF as a reference only

Page 11: 10 Top Tips for Good Object-Oriented Design

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

Page 12: 10 Top Tips for Good Object-Oriented Design

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

Page 13: 10 Top Tips for Good Object-Oriented Design

ANY QUESTIONS?Thank you for listening!