Creational pattern

In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or in added complexity to the design due to inflexibility in the creation procedures. Creational design patterns solve this problem by somehow controlling this object creation.

Overview

Creational design patterns are composed of two dominant ideas. One is encapsulating knowledge about which concrete classes the system uses. Another is hiding how instances of these concrete classes are created and combined.[1]

Creational design patterns are further categorized into object-creational patterns and class-creational patterns, where object-creational patterns deal with object creation and class-creational patterns deal with class-instantiation. In greater details, object-creational patterns defer part of its object creation to another object, while class-creational patterns defer its object creation to subclasses.[2]

Five well-known design patterns that are parts of creational patterns are the

  • abstract factory pattern, which provides an interface for creating related or dependent objects without specifying the objects' concrete classes.[3]
  • builder pattern, which separates the construction of a complex object from its representation so that the same construction process can create different representations.
  • factory method pattern, which allows a class to defer instantiation to subclasses.[4]
  • prototype pattern, which specifies the kind of object to create using a prototypical instance, and creates new objects by cloning this prototype.
  • singleton pattern, which ensures that a class only has one instance, and provides a global point of access to it.[5]

Definition

The creational patterns aim to separate a system from how its objects are created, composed, and represented. They increase the system's flexibility in terms of the what, who, how, and when of object creation. [6]

Usage

As modern software engineering depends more on object composition than class inheritance, emphasis shifts away from hard-coding behaviors toward defining a smaller set of basic behaviors that can be composed into more complex ones.[7] Hard-coding behaviors are inflexible because they require overriding or re-implementing the whole thing in order to change parts of the design. Additionally, hard-coding does not promote reuse and makes it difficult to keep track of errors. For these reasons, creational patterns are more useful than hard-coding behaviors. Creational patterns make design become more flexible. They provide different ways to remove explicit references in the concrete classes from the code that needs to instantiate them.[8] In other words, they create independency for objects and classes.

Consider applying creational patterns when:

  • A system should be independent of how its objects and products are created.
  • A set of related objects is designed to be used together.
  • Hiding the implementations of a class library or product, revealing only their interfaces.
  • Constructing different representation of independent complex objects.
  • A class wants its subclass to implement the object it creates.
  • The class instantiations are specified at run-time.
  • There must be a single instance and client can access this instance at all times.
  • Instance should be extensible without being modified.

Structure

Creational Pattern class diagram.

Below is a simple class diagram that most creational patterns have in common. Note that different creational patterns require additional and different participated classes.

Participants:

  • Creator: Declares object interface. Returns object.
  • ConcreteCreator: Implements object's interface.

Examples

Some examples of creational design patterns include:

  • Abstract Factory pattern: a class requests the objects it requires from a factory object instead of creating the objects directly
  • Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations
  • Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations
  • Dependency Injection pattern: a class accepts the objects it requires from an injector instead of creating the objects directly
  • Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed
  • Object pool pattern: avoid expensive acquisition and release of resources by recycling objects that are no longer in use
  • Prototype pattern: used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects
  • Singleton pattern: restrict instantiation of a class to one object

See also

References

  1. ^ Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995). Design Patterns. Massachusetts: Addison-Wesley. p. 81. ISBN 978-0-201-63361-0. Retrieved 2015-05-22.
  2. ^ Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995). Design Patterns. Massachusetts: Addison-Wesley. ISBN 978-0-201-63361-0. Retrieved 2015-05-22.
  3. ^ Freeman, Eric; Freeman, Elisabeth; Sierra, Kathy; Bates, Bert (2004). Hendrickson, Mike; Loukides, Mike (eds.). Head First Design Patterns. California: O'Reilly Media. p. 156. ISBN 978-0-596-00712-6. Retrieved 2015-05-22.
  4. ^ Freeman, Eric; Freeman, Elisabeth; Sierra, Kathy; Bates, Bert (2004). Hendrickson, Mike; Loukides, Mike (eds.). Head First Design Patterns. California: O'Reilly Media. p. 134. ISBN 978-0-596-00712-6. Retrieved 2015-05-22.
  5. ^ Freeman, Eric; Freeman, Elisabeth; Sierra, Kathy; Bates, Bert (2004). Hendrickson, Mike; Loukides, Mike (eds.). Head First Design Patterns. California: O'Reilly Media. p. 177. ISBN 978-0-596-00712-6. Retrieved 2015-05-22.
  6. ^ Judith, Bishop (2007). C# 3.0 Design Patterns. California: O'Reilly Media. p. 336. ISBN 978-0-596-52773-0. Retrieved 2015-05-22.
  7. ^ Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995). Design Patterns. Massachusetts: Addison-Wesley. p. 84. ISBN 978-0-201-63361-0. Retrieved 2015-05-22.
  8. ^ Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1995). Design Patterns. Massachusetts: Addison-Wesley. p. 85. ISBN 978-0-201-63361-0. Retrieved 2015-05-22.

Read other articles:

British chemist (1938–2020) SirJack BaldwinFRSBornJack Edward Baldwin(1938-08-08)8 August 1938London, England, U.KDied5 January 2020(2020-01-05) (aged 81)NationalityBritishAlma materImperial College LondonKnown forBaldwin's rulesAwards FRS (1978) Knight Bachelor (1997) Nakanishi Prize (2002) Scientific careerInstitutionsUniversity of OxfordDoctoral advisorDerek BartonDoctoral studentsJohn Sutherland Websiteresearch.chem.ox.ac.uk/jack-baldwin.aspx Arms of Sir Jack Baldwin: Arg...

Peta Teluk Biscay. Pantai Teluk Biscay - San Juan de Gaztelugatxe (Biscay). Teluk Biscay (Spanyol: Golfo de Vizcaya; Prancis: Golfe de Gascony) adalah sebuah teluk di Samudra Atlantik Utara. Teluk ini berada di sepanjang pantai barat Prancis dari Brest, hingga pantai utara Spanyol di Punta de Estaca de Bares. Teluk Biscay adalah tempat di mana sejumlah cuaca terburuk Samudra Atlantik terjadi. Hujan badai terjadi terutama selama musim dingin. Koordinat: 45°05′27″N 3°54′27″W&#...

Vassiliki Thanou-ChristophilouΒασιλική Θάνου-ΧριστοφίλουPerdana Menteri Yunani(Pelaksana tugas)Masa jabatan27 Agustus 2015 – 21 September 2015PresidenProkopis PavlopoulosPendahuluAlexis TsiprasPenggantiAlexis TsiprasPresiden Mahkamah KasasiMasa jabatan1 Juli 2015 – 10 September 2017PendahuluAthanasios KoutroumanosPenggantiVasileios Peppas Informasi pribadiLahir03 November 1950 (umur 73)Chalcis, YunaniPartai politikIndependenAnak3Alma materUni...

Ayi VivanandaWakil Wali Kota Bandung ke-4Masa jabatan16 September 2008 – 16 September 2013PresidenSusilo Bambang YudhoyonoGubernurDanny Setiawan Ahmad HeryawanWali kotaDada RosadaPendahuluH. Jusep PurwasugandaPenggantiOded Muhammad Danial Informasi pribadiLahir19 Juni 1967 (umur 56)Bandung, Jawa BaratKebangsaanIndonesiaPartai politik  PDI-PAnakIndriani Putri RohayatiAlma materUniversitas PadjadjaranPekerjaanPolitisi DosenSunting kotak info • L • B H...

Grundstein der Michaeliskirche in Hildesheim aus dem Jahr 1010. Grundstein des Kastells Saalburg vom 11. Oktober 1900 Grundsteinlegung für das Haus einer Freimaurerloge in Washington (1909), nach alter Tradition der Steinmetze mit dem Grundsteinhammer Präsident Lech Kaczyński bei der Grundsteinlegung für das Museum der Geschichte der polnischen Juden in Warschau Schautaler zur Grundsteinlegung der Kapelle im Schloss Moritzburg bei Dresden Die Grundsteinlegung ist im Bauwesen eine Zeremoni...

العلاقات الغانية القيرغيزستانية غانا قيرغيزستان   غانا   قيرغيزستان تعديل مصدري - تعديل   العلاقات الغانية القيرغيزستانية هي العلاقات الثنائية التي تجمع بين غانا وقيرغيزستان.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: و

Theory of perception Not to be confused with the psychotherapy of Fritz Perls, Gestalt therapy. This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Gestalt psychology – news · n...

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada.Este aviso fue puesto el 4 de abril de 2020. Buffalo Bill and the Indians, or Sitting Bull's History Lesson Título Buffalo Bill y los indiosFicha técnicaDirección Robert AltmanProducción Robert AltmanGuion Alan RudolphRobert Altman Novela Indians de Arthur L. KopitMúsica Richard BaskinFotografía Paul LohmanMontaje Peter Appleton Dennis M. HillVestuario Anthony PowellProtagonistas Paul Newman Joel...

British Army general (1803–1883) General the Honourable SirCharles Hastings DoyleKCMGColonial Lieutenant Governor of Nova ScotiaIn office17 September 1863 – 8 November 1865MonarchVictoriaPremierJames W. JohnstonCharles TupperGovernorThe Viscount MonckPreceded byGeorge Phipps, 2nd Marquess of NormanbySucceeded byRichard Graves MacDonnell2nd Lieutenant Governor of Nova ScotiaIn office18 October 1867 – 1 May 1873MonarchVictoriaGovernors GeneralThe Viscount MonckThe Lord L...

Mazedo e Cortes Wappen Karte Mazedo e Cortes (Portugal) Basisdaten Region: Norte Unterregion: Alto Minho Distrikt: Viana do Castelo Concelho: Monção Koordinaten: 42° 4′ N, 8° 30′ W42.05871-8.50104Koordinaten: 42° 4′ N, 8° 30′ W Einwohner: 3817 (Stand: 19. April 2021)[1] Fläche: 12,13 km² (Stand: 1. Januar 2010)[2] Bevölkerungsdichte: 315 Einwohner pro km² Postleitzahl: 4950-850 Politik Adre...

For the Irish Jacobite soldier, see Nicholas Cusack (Jacobite). Kildare CathedralNicholas Cusack (died 5 September 1299) was a thirteenth-century Bishop of Kildare and member of the Franciscan Order.[1] He belonged to a prominent Anglo-Irish family from County Meath, who were tenants-in-chief to Baron Skryne, and were later based mainly at Cushinstown, County Meath. Walter de Cusack of Gerrardstown (died 1334), the leading judge and military commander, was a cousin. Nicholas clearly r...

1962 in the Vietnam War ← 19611963 →LocationIndochinaBelligerents Anti-Communist forces:  South Vietnam United States Kingdom of Laos Communist forces:  North Vietnam Viet Cong Pathet LaoCasualties and losses US: 53 killed[1]South Vietnam: 4,457 killed[2] North Vietnam: 21,158 killed vteMilitary engagements during the Vietnam WarGuerrilla phase Laos Biên Hòa Đồng Khởi Chopper Palace Bombing Sunrise Shufly Ấp Bắc Go Cong Hiep Hoa ...

December night in Molde. The Molde panorama is the renowned panoramic view of some 222 partly snow-clad peaks, seen from the town of Molde in Molde Municipality in Møre og Romsdal county, Norway. It can be observed from all over the town, but the viewpoint from the top of Varden, a 404-metre (1,325 ft) tall hill behind the city, is generally considered to offer the best view.[1] The mountains of the panorama are located about 15–40 kilometres (9.3–24.9 mi) to the south,...

Hong Kong swimmer In this Hong Kong name, the surname is Au. In accordance with Hong Kong custom, the Western-style name is Stephanie Au and the Chinese-style name is Au Hoi-shun. Stephanie Au歐鎧淳Stephanie Au at the 2009 East Asian GamesPersonal informationFull nameStephanie Au Hoi-shunNational team Hong KongBorn (1992-05-30) 30 May 1992 (age 31)Hong KongHeight1.73 m (5 ft 8 in)Weight56.5 kg (125 lb)SportSportSwimmingStrokesBackstroke, freestyleCol...

For the plaintiff in the 1992 lawsuit against the Kellogg Company, see Pop-Tarts § History. Lt.-Col. (Rev.) Thomas Nangle Thomas Matthew Mary Nangle (1889 – January 4, 1972) was a Newfoundland cleric, military chaplain of the Royal Newfoundland Regiment during World War I, diplomat and later a Rhodesian politician and farmer. Early life He was born in St. John's, Newfoundland and educated at St. Bonaventure College before attending All Hallows College seminary in Dublin and St. Patric...

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Runaway with Del Shannon – news · newspapers · books · scholar · JSTOR (November 2023) (Learn how and when to remove this template message) 1961 studio album by Del ShannonRunaway with Del ShannonStudio album by Del ShannonReleasedJune 1961GenreRock and...

Alí Asjádovich Shoguentsúkov Alí Asjádovich Shoguentsúkov (en cirílico ruso: Али́ Асха́дович Шогенцу́ков, kabardino:ЩоджэнцIыкIу Iэсхьэд и къуэ Алий, Bekhisen, Óblast de Tersk, 28 de octubre de 1900-Babruisk, Bielorrusia, 29 de noviembre de 1941) fue un profesor, escritor y traductor kabardino.[1]​ Biografía Estudió en la madraza y el instituto pedagógico de Bekhisen y luego en Estambul, más tarde regresó a Kabardia-Balkaria...

Series of anthologies edited by Isaac Asimov The Hugo Winners First editionEditorIsaac AsimovCountryUnited StatesLanguageEnglishGenreScience fictionPublisherDoubledayPublication date1962Media typePrint (hardback)Pages318Followed byThe New Hugo Winners  The Hugo Winners was a series of books which collected science fiction and fantasy stories that won a Hugo Award for Short Story, Novelette or Novella at the World Science Fiction Convention between 1955 and 1982. Each volume was...

For other bridges, see Newport Bridge (disambiguation). Bridge in NewportNewport BridgeNewport Bridge in 2011.Coordinates51°35′26″N 2°59′38″W / 51.5905°N 2.9938°W / 51.5905; -2.9938CarriesMotor vehicles, cyclists and pedestriansCrossesRiver UskLocaleNewportOfficial nameNewport BridgeMaintained byNewport City CouncilCharacteristicsDesignFive-span arch bridgeTotal length? feet (? metres)WidthFour-lane carriageway, two cycle/footpathsLongest span? m (?...

American multinational retail chain Wild Birds UnlimitedFounderJim CarpenterHeadquartersCarmel, Indianapolis, United StatesKey peopleJim Carpenter (CEO)ProductsBird-feeding suppliesBird-watching suppliesBirdhousesFeedersBinocularsParentWild Birds Unlimited Inc. Wild Birds Unlimited is a retail store that specializes in bird seed, bird feeders, and many other bird feeding supplies. Jim Carpenter opened the first Wild Birds Unlimited store in 1981 in Indianapolis, Indiana. By 1983, Carpenter st...