Posts

Showing posts from February, 2016

Adapter design pattern for beginners.

Image
Background – Think about a situation where a Chinese person has to communicate to an Indian person. Where Chinese person doesn’t speak Hindi, and Indian person doesn’t speak Chinese. I know you already knew the solution :). Find a third person who understand Chinese, and Hindi both, and translate both ways so that they can communicate. Congratulations! If you understand above mentioned small concept, you know, adapter design pattern as well. This design pattern had come from the hardware industry. Look at the below mentioned diagram - You must have seen many hardware adapters in your life. India's electronic boards designed for round pins, but not in the US. So if you have purchased your laptop from the US, you will have a different charge pin. Like mentioned in the above diagram. You need an adapter. When homogeneous systems talks to each other. We need adapters to make the compatible connections/communication. In software, we have different OS, languag

Flyweight design pattern for beginners.

Image
Problem statement – Flyweight is one of the complex design patterns. Understanding it will be comfortable through a proper, step-by-step example. Be patient and try to follow the below-mentioned concept. We will understand the problem statement of the Flyweight design pattern completely t hrough text editor example. Try to develop a text editor. You will learn many design patterns from text editor application implementation. Think about a text editor page. As per standards, a line contains 80 alphabets, and a page contains 30 lines. Let us model a text editor page. It is nothing but a row and column base structure, like matrix, which can hold one character at a time. In any particulate location.  The smallest structure/unit of text editor is alphabet (a,b,c, .., z). One location will contain one alphabet, which may have its own font, size, color, style, etc. If I consider those smallest units as objects, represented at a particular location on text editor. We will en