Structural

How objects relate to each other.

Adapter

Bridge

Composite

Composition Root

It is the main entry file for an application and where you instantiate everything used by the application.

Decorator

  • To extend an object, without changing the original object implementation.

  • Is used for the O of SOLID.

    • Open to extension, Closed to modification.

  • Ex.: You make the DecoratedComponent implement the same interface as the object you want to extend. And in the DecoretedComponent constructor you pass the original component as an argument.

class DecoratedComponent implements SomeObject {
	constructor (readonly obj: SomeObject) {
	}

	someFunc() {
		[extendDoingMoreStuff]
		...
		return this.obj.func()
	}
}

$Decorator \neq Middleware$, since middle kind of chains the layers in an array, and the decorators chains them kind of like recursively, one is inside of the other.

Facade

  • It is all about simplicity.

  • It's like a simplified 'mask' that will hide all the complexity for the outside.

  • You can encapsulate complex classes and functionalities with simpler classes that will deal with the complexity themselves and expose only simple statements.

    • Ex.: The Jquery is a Facade for some functions that deal with DOM manipulation.

Flyweight

Proxy

Designed to intercept a call, and do more stuff before releasing it.

Javascript natively supports it with new Proxy() .

Ex.: Frameworks like VUE use proxy to deal with reactivity for variable changes.

Last updated