Overview

Anti Patterns

Anti patterns are certain patterns in software development that is considered a bad programming practice. God Object is example of Anti-Pattern. Here God Object means all operations are performed only one object. For example,

public class GodObject {
   function PerformInitialization () {}
   function ReadFromFile () {}
   function WriteToFile () {}
   function DisplayToScreen () {}
   function PerformCalculation () {}
   function ValidateInput () {}
   // and so on... //
}

Here the object performed all operations. The basic idea behind object-oriented programming is that a big problem is separated into several smaller problems (a divide and conquer strategy) and solutions are created for each of them. Once the small problems have been solved, the big problem as a whole has been solved. Therefore an object need only know everything about itself.

The opposed patterns of Anti patterns are Designed patterns.

Design Patterns

Which comes as a solution for real time problems of application development. A Design pattern is a general reusable solution to a commonly occurring problem within a given context in a software design.  Design patterns are considered as a good programming practice in application development or software development. For example,

public class FileInputOutput {
   function ReadFromFile () {}
   function WriteToFile () {}
}

public class UserInputOutput {
   function DisplayToScreen () {}
   function ValidateInput () {}
}

public class Logic {
   function PerformInitialization () {}
   function PerformCalculation () {}
}

My main intention is due to the problems faced in designing the software applications. Most of the time what happen is we design the software we implement them and by the time we ready to deliver the product to the customer. When that time client changes the requirements and due to this change of requirement then we have to do lots of changes in the code before deliver it to the customer. Due to this we face many problems as for as the implementation goes. In order to prevent these problems we use design patterns.

Design pattern is the generic solutions to the common problems which are encountered in object oriented software design. Here very important point is changes are minimal. Patterns are language and domain independent strategies for solving common object oriented design problems. Design patterns are mainly divided into 3 types

  1. Creational Design Patterns
  2. Structural Design Patterns
  3. Behavioral Design Patterns
1. Creational Design Patterns

Creational design patterns are concerned with the way of creating objects. These design patterns are used when a decision must be made at the time of instantiation of a class (i.e. creating an object of a class). But everyone knows an object is created by using new keyword in java. For example:

Student s1 = new Student (); 

Hard-Coded code is not the good programming approach. Here, we are creating the instance by using the new keyword. Sometimes, the nature of the object must be changed according to the nature of the program. In such cases, we must get the help of creational design patterns to provide more general and flexible approach. There are 6 types of creational design patterns.

  1. Singleton Pattern
  2. Factory Pattern / Factory Method
  3. Abstract Factory Pattern
  4. Prototype Pattern
  5. Builder Pattern
  6. Object Pool Pattern
2. Structural Design Patterns

Structural patterns provide different ways to create a class structure, for example using inheritance and composition to create a large object from small objects. Structural design patterns are concerned with how classes and objects can be composed, to form larger structures. The structural design patterns simplifies the structure by identifying the relationships. There are following 7 types of structural design patterns.

  1. Adapter Pattern
  2. Bridge Pattern
  3. Composite Pattern
  4. Decorator Pattern
  5. Facade Pattern
  6. Flyweight Pattern
  7. Proxy Pattern
3. Behavioral Design Patterns

Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns,the interaction between the objects should be in such a way that they can easily talk to each other and still should be loosely coupled. That means the implementation and the client should be loosely coupled in order to avoid hard coding and dependencies. There are 12 types of structural design patterns

  1. Chain of Responsibility Pattern
  2. Command Pattern
  3. Interpreter Pattern
  4. Iterator Pattern
  5. Mediator Pattern
  6. Memento Pattern
  7. Observer Pattern
  8. State Pattern
  9. Strategy Pattern
  10. Template Pattern
  11. Visitor Pattern
  12. Null Object
Overview
Scroll to top