Design patterns

What to Avoid in Your Design

This note will list few things you should try to avoid in your design. Please also see notes on SOLID Principles and summary of additional design principles and best practices.

  1. Run-Time Type Identification (RTTI)

    • Design that require you to check for the actual type of the reference object should be avoided (e.g. if(type(something) = something, do something). 

  2. Cyclomatic complexity (CC)

SOLID Principles of Design

SOLID is a mnemonic acronym introduced by Michael Feathers for five of the principles named by Robert C. Martin, and when applied together, these intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time.

  1. (++) Single responsibility principle (SRP)

    • Every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. 

Important UML Diagrams Required to Work with Design Patterns

There is a saying that a picture can speak thousand words. UML diagrams are those pictures which can speak all those words about your design. There are many categories of UML diagrams. However this note will contain only those class diagram components that are really required for representing your design decisions, design patterns and principles.

Observer Design Pattern

Observer pattern is a behavioral design pattern where a collection of objects called observers listens for the state change of another object called subject. Observer pattern defines a one-to-many relationship between the subject and one or more of observers. The subject object maintains a list of its observer objects, and notifies those observers automatically if there are any state changes for the subject, usually by calling one method of the observer.

[Learning Plan] Three Phase Design Patterns Learning Strategy

We will follow a three phase learning program for design principles and patterns. 

  1. We will first learn principles and will see theoretical explanation to patterns along with the principles they are linked to. This will help you get a clear understanding of the principles and little bit knowledge on patterns. 

Strategy Design Pattern (aka Policy Pattern)

The strategy pattern is a behavioral pattern that defines a family of algorithms, encapsulates each one of them and makes them interchangeable. According to this pattern, a different class is created for each interchangeable algorithm, and this class can be injected anytime, even at runtime.  

 

Components and working of Strategy Pattern

Important components of strategy pattern are:

Factory Design Patterns - Simple Factory, Factory Method, Static Factory Method and Abstract Factory

There are different types of factory patterns like Simple Factory (Or Class Factory), Factory Method, Abstract Factory Method and Creator Method (Or Static Factory Method). Out of these, Factory Method and Abstract Factory Method are part of the GoF Design Patterns. All factory design patterns help you create objects without using the new keyword directly within your code. Concept is similar to any other real world factories: You use cars, but you don’t develop cars by your own.

Summary of the GoF Design Patterns

Design patterns gained popularity in computer science after the book Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994 by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides; and together they are called the "Gang of Four" or "GoF".

The GOF design patterns can be broadly classified into the following three categories:

  1. Creational patterns

    • These are patterns related to object creation. 

Additional Object Oriented Design Principles and Best Practices

Object Oriented Design principles are very important and are sometimes considered even more important than design patterns. All design patterns are based on one or more of the design principles. Having thorough understanding of the design principles will help you understand the design paterns better and faster, and will even help you solve many design scenarios if you can't find a design pattern fitting that scenario.

Factory and Abstract Factory Patterns

Factory pattern is a design pattern used to create objects. Similar to a car factory that creates different models of cars, an object factory will create different type of objects. The abstract factory pattern provides a way to encapsulate a group of similar or related factories. Hence the abstract factory can be considered as a factory of factories.  

 

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!