Dependency Inversion Principle states to “Depend on abstractions and not upon concretions”. What this principle means is that rather than writing code that refers to concrete classes, you should code for Interfaces and Abstract classes. For example, if Class B instantiates Class A, then it gets dependent on the Class A. Class A { // …
Continue reading Dependency Inversion Principle in JavaDesign Pattern
Iterator Pattern This pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. [GOF definition] This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation. Iterator Pattern …
Continue reading Iterator Pattern in JavaState Pattern Definition The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.[GOF definition] Implementing State Pattern For implementing State pattern, we need a class that carries state. We call this class as Context. Then we need a State …
Continue reading State PatternCommand Pattern Definition Command pattern encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. [GOF definition] Understanding Command Pattern Following terms are associated with the Command Pattern : Client The client object is responsible for creating a …
Continue reading Command PatternTemplate Method Pattern Definition This pattern defines the skeleton of an algorithm in an operation, deferring some steps to subclasses. The template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.[GoF definition] Understanding Template Method Pattern This pattern focuses on creating a template for an algorithm. One …
Continue reading Template Method Pattern