Clean Code Slides-Objects
Clean Code Slides-Objects
The ability of an
object to take on
many forms.
Classes Should Be Small
How much are your class methods using the class properties?
All methods each use all All methods don’t use any class
properties Highly properties
cohesive
classes Data structure / container with
A highly cohesive object
utility methods
Law Of Demeter
this.customer.lastPurchase.date;
Code in a method may only access direct internals (properties and methods) of:
• the object it belongs to
• objects that are stored in properties of that object
• objects which are received as method parameters
• objects which are created in the method
Tell, Don’t Ask!
The SOLID Principles
O Open-Closed Principle
Objects should be
replaceable with instances
of their subclasses without
altering the behavior.
The Interface Segregation Principle (ISP)
Many client-specific
interfaces are better than
one general purpose
interface.
The Dependency Inversion Principle (DIP)