- Inheritanceis tightly coupled.
- Inheritance is basically used for polymorphism which can be done in other ways to.
- Generally over a time we duplicate our code in inherited services across project which is good once or twice but if it happens third time then we need to rethink our strategy. This is also called as “The rule of thirds”.
- For example if we have Following services in our project
- Access control
- Publish subscribe
- Workflow
- Common components
- Entity master
- So we might be adding same function for access control in publish subscribe as well as workflow service.
- Sometimes it is not good to share code among various projects.
- A base class should not have methods that are not required by descendants.
- Same class may be at different level of inheritance in different projects.
- We might be exposing functionality to descendants that we don’t want to expose.
- Instead of putting all the different configurations into one file and inherit it we can distribute them in different classes.
- Message Broker Settings
- Postgres SQL settings
- Storage account settings
- We can use composition of these classes in our project. So each class will have only configuration that it requires.
- In the above example we have inheritance of only reusable code but for different settings we are using composition. So no Services code is with each other and each service has only required code.
No comments:
Post a Comment