Design pattern
From Wikipedia, a free encyclopedia written in simple English for easy reading.
In Computer science, a Design pattern is an abstract solution to a certain problem. Design patterns are used in object oriented programming. They give a possible solution to a problem of designing software.
Design patterns came en vogue around 1995. They also simplify the language between computer scientists. Ideally, a design pattern should be reusable many times. It is like a brick of a house, it can be used for many different problems. One can also build bridges with bricks, not only houses.
[edit] Examples
These examples are actual examples of design patterns as they are in use. They have not been simplified. It is only the language used to describe them that has been made simpler.
[edit] Flyweight
In a text-processing system, each word or letter can have some attributes (like, eg. formating, typeface, size, position on the page...). It would be possible to create a new object for each character in the document, and give it these attributes. This is extemely expensive, however.
So what people do is they create one object for each type of formatting they have, and link that to the information what letter it is. That needs a lot fewer objects. Smart people who found this, called the pattern Flyweight.
[edit] Singleton
Another easy to understand pattern is called Singleton. It is used when there can only be one instance of a given class. That class usually has some static method (eg. getInstance()) which returns a new instance. It also saves the instance internally. So if it already created the instance, it can simply return it.
public class Singleton { Object theInstance=null; public Object getInstance() { if (theInstance==null) { theInstance=new Object();} return theInstance; } }
This short article needs someone to make it better.
You can help Wikipedia by adding to it.