Structural design patterns are software patterns that help in solving standard problems in creating static structure of classes through inheritance and composition.
Do check the design patterns catalogue page.
Do not miss the creational patterns and behavioral patterns pages too.
2 variants in this –
- Object adapter – The wrapper contains the instance of the class it wraps. Do check the C# example of object adpater.
stack
is the adatee and theprogram
is the adapter. - Class adapter – Uses inheritance to wrap the adpatee.
3 variants –
- Static facade – Facade is implemented as a set of static methods.
- Opaque facade – Only facade is visible outside the sub-system. Often the facade is implemented as singleton in this case.
- Transparent facade – The facade and the internal implementation interfaces in the sub-system are exposed outside.
Facade pattern Vs adapter pattern – Facade often aggregates the internal APIs and define an abstracted set of APIs whereas the adapter just wraps the existing APIs.
Do read C# implementation of facade pattern.
Simple scenario of taking order in restaurant is presented in this sample implementation of decorator pattern in C#. Basic menu is bread. With every topping such as chicken, the price of the order goes up. Toppings are introduced as decorators.
A sample scenario of thread scheduling in operating systems have been explained in this C# implementation. Two concepts – Thread scheduling mechanism and platforms used here. They could grow independently. Adding a new platform shall not impact the scheduling algoithm and vice versa. This is made possible via bridge pattern creating an orthogonal hierarchy among them.
Serializable
– signifies that it can be flattened and written to disk/network socket, Cloenable
– signifies that the implementation can be legally cloned.