Posts

Showing posts with the label Design Patterns

Proxy Design Pattern in Java

Image
Gang of Four Definition:    Provide a surrogate or placeholder for another object to control access to it. Computer World Example: Consider an ATM implementation for a bank. Here we will find multiple proxy objects. Actual bank information will be stored in a remote server. We must remember that in the real programming world, the creation of multiple instances of a complex object (heavy object) is very costly. In such situations, we can create multiple proxy objects (which must point to an original object) and the total creation of actual objects can be carried out on a demand basis. Thus we can save both memory and creational time. Explanation: In the following program, we are calling the doSomework() function of the proxy object, which in turn calls the doSomwork() of the concrete object. With the output, we are getting the result directly through the concrete object. For this example, I have created different packages, proxy implementations will be reside in ...

In Detail: Strategy Design Pattern In Java

In this post i am going to explain about Strategy Design pattern. First of all,  What is Strategy Design Pattern? Let's see the definition first. The strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Very hard to understand, right? This is a high level explanation of Strategy design pattern. Don't explain this definition to beginners. Let's see what is Strategy design pattern in detail, with an example. first, it is a behavioral design pattern. To understand this pattern, you should know the below terminology & concepts of Object oriented programming language. 1. Inheritance, 2. Composition, 3. IS-A , HAS-A relationship, 4. Interface driven programming, 5. Polymorphism. Let's start with an example problem. Consider, we have a base class Animal and 2 sub classes Parrot, Cat (Inheritance). package com.speakingcs.design...