Few days back I wrote for Solid and Grasp principles for
oops
Now I am again extending it to make it more matured way to
write code.
Let start with coupling and cohesion.
Loose/Low Coupling
- low dependency between classes;
- low impact in a class of changes in other classes
- high reuse potential
High Cohesion
- measure of how strongly-related or focused the responsibilities of a single module are
- If methods of a class tend to be similar in many aspects, then the class have high cohesion
- In highly-cohesive system, code readability and the likelihood of reuse is increased, while complexity is kept manageable.
Also check
- Encapsulate what varies
- Favor Composition over Inheritance
- Program to interface not implementation
- Strive for loosely coupled design between objects that interact
For Interfaces
- Like an abstract base class: any non-abstract type inheriting the interface must implement all its members.
- Cannot be instantiated directly.
- Can contain events, indexers, methods and properties.
- Contain no implementation of methods.
- Classes and structs can inherit from more than one interface.
- An interface can itself inherit from multiple interfaces.
·
Difference between Interface and abstract base class
- Abstract class can have non abstract methods, methods of an interface are effectively abstract since they contain only the signature
- A class can implement any no of interfaces, but can subclass at most one abstract class.
- An abstract class can declare and use variables, an interface cannot.
- An abstract class can have methods whose access is public, internal, protected, protected internal and private. Interface members implicitly have public access.
- An abstract class can declare constructor, an interface cannot.
- An abstract class can have delegate, an interface cannot
Comments
Post a Comment
Important - Make sure to click the Notify Me check-box below the comment to be notified of follow up comments and replies.