Implementation of design patterns (Implementations using Java and Kotlin)
Used in managing undo feature of an applications
Design Diagram of the implementation - In theoritacal implementation we can say
Editor - Originator
EditorState - Momento
EditorHistory - Care taker
The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes.
Design Diagram of the implementation - In theoritacal implementation we can say
Canvas - Context
Tool - State
BrushTool - Concrete implementation
SelectionTool - Concrete implementation
A source of command objects and a series of processing objects.It allows to crete chain of jobs here I took the use case of a web server
Design Diagram of the implementation - In theoritacal implementation we can say
Webserver invokes following operations
Chain of operations :
Auth -> Logging -> Compression
At any given time user remove operations from the chain. And you don't need to update Webserver class.
This proves SOLID
O -> Open for extention (Classes should open for extention and close for modifications) this is a great example for tha
Way of separating an algorithm from an object structure on which it operates. Most suitable for introducing new operations to an existing platform
-
Design Diagram of the implementation - Let's take a Html Document as an example here HtmlElement -> Interface to child html elements it has this method : execute(operation : Operations) : String AnchorElement -> Child ui element HeaderElement -> Child ui element
Operation -> Interface to apply operations to each element implements apply(htmlElement : HtmlElement) HighlightOperations -> apply(htmlElement : HtmlElement) : String TextHintingOperation -> apply(htmlElement : HtmlElement) : StringThis will again proves Open for extention principle. Imagine in future if you want to add a new operation just need to add a sub classs that implements operations interface However in this example we can say html ui elements are more stable and we don't have infinite no of elements (We know what's the elements of tags exists) still so this pattern is more usful.

