Posts

Showing posts from December, 2017

Template Method Design Pattern

Image
Intent Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. Structure Image : Template method design pattern structure Participants 1. AbstractClass defines abstract primitive operations that concrete subclasses define to implement steps of an algorithm. implements a template method defining the skeleton of an algorithm.The template method calls primitive operations as well as operations defined in AbstractClass or those of other objects.  2. ConcreteClass  implements the primitive operations to carry out subclass-specific steps of the algorithm. Collaborations ConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm. Source Code Follow the steps to implementation of Template design pattern. Let's create a coffee beverage system Step 1: Create  CaffeineBeverage class ,which defines skeleton for the

Design Patterns Overview

Image
Design Patterns In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Uses of Design Patterns Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns. Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn&

Observer Design Pattern

Image
? prev next ? Intent It belongs to  behavioral design patterns  catalog. Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Also known as Dependents, Publish-Subscribe Structure  Participants 1. Subject knows its observers. Any number of Observer objects may observe a subject. provides an interface for attaching and detaching Observer objects. 2. Observer defines an updating interface for objects that should be notified of changes in a subject. 3. ConcreteSubject stores state of interest to ConcreteObserver objects. sends a notification to its observers when its state changes. 4. ConcreteObserver maintains a reference to a ConcreteSubject object. stores state that should stay consistent with the subject's. implements the Observer updating interface to keep its state consistent with the subject's. Collaborations ConcreteSubject notifies its observers whenever a change occurs that coul