Single Responsibility Principle Open/Closed Principle @theadoranwodo Open to extensions and closed to modifications _______________________________ Practice coding to abstractions, rather than core implementations
Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle @theadoranwodo Functions that use references to base classes must be able to use objects of derived classes without knowing it.
Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle @theadoranwodo Don’t make clients depend on methods they don’t use
Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle @theadoranwodo interface Vehicle { void brake(); void truttle(); void clutchDown (); } class MyPrado implements Vehicle{ void brake(){ // code here } void clutchDown (){ /* I don’t need this method but I have to implement it by force so I’d just throw an exception here */ throw new UnsupportedException(); } void truttle(){ // code here } } Don’t do this
Single Responsibility Principle Open/Closed Principle Liskov Substitution Principle Interface Segregation Principle Dependency Inversion Principle @theadoranwodo High level modules should not depend on low level modules, both should depend on abstractions. ________________________________________ Abstractions should not depend on details but details should depend on abstractions
different Your application should have two types of classes: - Factories for creating new objects. - Application classes that contain the business logic for your app.
class Person{ private int buildCode; Person(BuilderHelper helper, int seed){ buildCode = helper.getCodeBuilder () . generateCode (seed) . build(); } } Don’t do this