- You cannot extend or inherit more than 1 abstract class (C# does not provides multiple inheritance.)
- Struct cannot implement an abstract class.
- Struct can implement interfaces.
class MyClass : a,b ---ERROR--Cannot implement multiple base class.
abstract class a
abstract class b
Abstract class gives you all the benefits that interfaces does,except very important one feature “Multiple Inheritance“. This is the sole reason why we are asked to write “program to an interface”.You would argue that i would load a constructor with a abstract class rather than interface,but it would fail since you cannot implement more than one class and you need interface to do that.
Liskov Substitution Principle: SubType (Child Class)Must be Substitutable For Base Type(Base Class).
LSP comes into use when you use inheritance/Abstraction.
1.Child Class Should not remove Base Class Behaviour.
2.Child Class Should not violate base class invariants.
In short,the Calling code should not know whether it is calling the base class or derived class.
1.It is essential when you need only one instance of a class.
2.The Class itself is responsible for maintaining only one instance of class(Breaks Single Responsibility).
3.They make the System Tightly Coupled.
2.Thread Safe-Single Lock
3.Thread Safe -Double Check Lock
4.Thread Safe-Lazy Loading.
Source Code of SingleTon
Split the Large Blocks of Code into Smaller Blocks.
Rule of Thumb:
1.Make Sure Large Blocks are Made Small-This is made via Functions/Methods.
2.Make Sure Your Function Does only one thing .Not more than that.
When to Use Decorator Pattern?
Add New Responsibility(functionality) to the class,without breaking the existing functionality.
1.Component as abstract class/Interface.
2.Concrete Components Implementing the Components.
3.Decorator as abstract class/Interface with Component as member initialized via constructor.
4.Concrete Decorator Implements Decorator.
Functionality are added at runtime,Hard to debug(Since object implements both Concrete Component and Concrete Decorator).