Symptoms
- difficult to change
- every change cascades changes in other dependent modules
- software break in many places, with every change
- inability to reuse from other projects or from the same project
- design preserving changes are harder than hacks
- changing requirements
- improper dependencies between the modules
- OCP (open close principle), module should be open to extension but close for modification,
- means the ability to change what modules do without changing the source code of the module
- abstraction is the key to OCP
- dynamic polymorphism(virtual functions) and static polymorphism (templates) are way to achieve OCP
- LSP (Liskov Substitution Principle), subclasses should be substitutable by their base class
- a user of base class should continue to function properly if a derivative of the base class is passed to it
- in order to be substitutable the contract of the base class must be honored by the derived class
- contract of a method is stated by its preconditions(what will be true before entering in the function) and postconditions(what will be true after the function execution is complete).
- so a derived class is substitutable for its base class if
- derived class method preconditions are no stronger than the base class method
- derived class method postconditions are no weaker than the base class method
- DIP (Dependency Inversion Principle), depend upon Abstractions, not on concretions
- primary mechanism of OO architecture,idea behind component design COM, CORBA, EJB etc.
- every dependency in the design should target interface or an abstract class, as the concrete implementation changes a lot (most of the time)
- ISP (Interface Segregation Principle), many client specific interfaces are better than one general purpose interface
- needs of one client might differ from other client, when using the same interface, thus create client specific interface, and multiply inherit them into the concrete class
- the clients should be categorized by their type
- there is no harm in adding the same method to different interface of different clients, if both client need the same method
- change in existing interface, is discouraged, rather adding a new interface is recommended
No comments:
Post a Comment