[{"data":1,"prerenderedAt":2300},["ShallowReactive",2],{"post-\u002Ftr\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir":3},{"page":4,"translation":2143,"nav":2157,"related":2280,"random":2292},{"id":5,"title":6,"body":7,"categories":2141,"category":2143,"date":2144,"description":2145,"draft":2146,"extension":2147,"image":2148,"kind":2143,"lang":280,"meta":2149,"navigation":427,"path":2032,"readingTime":478,"seo":2150,"slug":2151,"stem":2152,"tags":2153,"translationKey":2143,"type":2142,"updated":2143,"__hash__":2156},"postsTr\u002Ftr\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir.md","Abstract Factory Tasarım Deseni Nedir?",{"type":8,"value":9,"toc":2127},"minimark",[10,43,52,65,68,71,76,83,85,89,92,135,142,148,151,157,162,165,167,171,180,186,191,214,220,225,244,247,252,257,268,273,335,337,341,346,349,352,354,358,396,398,402,406,1349,1353,2013,2015,2019,2024,2042,2047,2076,2081,2123],[11,12,13,21],"blockquote",{},[14,15,16,17],"p",{},"💡 ",[18,19,20],"strong",{},"Özet (TL;DR):",[22,23,24,31,37],"ul",{},[25,26,27,30],"li",{},[18,28,29],{},"Amacı:"," Birbiriyle ilişkili veya bağımlı nesne ailelerini, onların somut sınıflarını (concrete classes) belirtmeden oluşturmak için bir arayüz (interface) sağlayan oluşumsal (creational) bir tasarım desenidir.",[25,32,33,36],{},[18,34,35],{},"Çözdüğü Sorun:"," Kodun, ürün varyasyonlarının (örneğin Modern, Viktorya tarzı) somut sınıflarına sıkı sıkıya bağlanmasını önler ve ürünlerin birbiriyle uyumlu üretilmesini garanti eder.",[25,38,39,42],{},[18,40,41],{},"Yöntem:"," Her ürün varyasyonu için ayrı bir fabrika sınıfı (Concrete Factory) tanımlanır. İstemci kod, bu fabrikalarla ortak bir soyut fabrika arayüzü (Abstract Factory) üzerinden çalışır.",[14,44,45,46,51],{},"Bu yazı ",[47,48,50],"a",{"href":49},"\u002Ftr\u002Fdesign-patterns-tasarim-desenleri-nedir","Design Patterns\u002FTasarım Desenleri nedir?"," başlıklı yazı dizisinin bir parçasıdır.",[14,53,54,55,64],{},"Bu içerik ağırlıklı olarak ",[47,56,63],{"href":57,"rel":58,"target":62},"https:\u002F\u002Frefactoring.guru\u002Fdesign-patterns",[59,60,61],"nofollow","noopener","noreferrer","_blank","refactoring.guru"," sitesindeki içeriğin tercümesi ve derlenmesinden oluşturulmuştur.",[14,66,67],{},"Tüm tasarım desenleri ya da diğer adıyla tasarım kalıplarına yönelik ayrıntılı içeriklere yazının sonundaki bağlantılardan ulaşabilirsiniz.",[69,70],"hr",{},[72,73,75],"h2",{"id":74},"abstract-factory-tasarım-deseninin-amacı","Abstract Factory Tasarım Deseninin Amacı",[14,77,78,79,82],{},"Türkçeye birebir çevrildiğinde \"soyut fabrika\" gibi anlamsız bir ifadeye dönüşen ",[18,80,81],{},"Abstract Factory",", birbiriyle ilişkili sınıfları (class) ve metotların içeriğini belirtmeden nesneler oluşturmayı sağlar.",[69,84],{},[72,86,88],{"id":87},"sorun","Sorun",[14,90,91],{},"Bir mobilya mağazası simülatörü oluşturacağınızı düşünün. Kodunuz aşağıdakileri ifade eden sınıflar içermelidir:",[93,94,95,112],"ol",{},[25,96,97,100,101,105,106,105,109],{},[18,98,99],{},"İlgili ürünlerden oluşan bir ürün ailesi:"," Örneğin ",[102,103,104],"code",{},"Koltuk"," + ",[102,107,108],{},"Kanepe",[102,110,111],{},"Sehpa",[25,113,114,100,117,105,120,105,122,124,125,105,128,105,131,134],{},[18,115,116],{},"Bu ailenin çeşitli varyasyonları:",[102,118,119],{},"Sandalye",[102,121,104],{},[102,123,111],{}," ürünlerinin ",[102,126,127],{},"Modern",[102,129,130],{},"Viktorya (Victorian)",[102,132,133],{},"Art Deco"," gibi varyasyonları.",[14,136,137],{},[138,139],"img",{"alt":140,"src":141},"Product families and their variants.","\u002Fimages\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir\u002Fproblem-en.avif",[14,143,144],{},[145,146,147],"em",{},"Ürün aileleri ve varyantları.",[14,149,150],{},"Oluşturacağınız mobilyaların bir şekilde ürün ailesinin diğer üyeleriyle eşleşmesi gerekir. Müşteriler, birbiriyle uyumsuz ürünlerle karşılaştığında hayal kırıklığına uğrayacaktır.",[14,152,153],{},[138,154],{"alt":155,"src":156},"","\u002Fimages\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir\u002Fabstract-factory-karikatur.avif",[14,158,159],{},[145,160,161],{},"Modern görünümlü bir kanepe, Viktorya tarzı koltuklarla pek hoş görünmez.",[14,163,164],{},"Yeni ürün aileleri veya ürünler eklendiğinde mevcut kodunuzu tamamen değiştirmek de istemezsiniz. Mobilya üreticilerinin modellerini sürekli güncelledikleri düşünüldüğünde, bu durum yazılım geliştirme sürecinde sıkça karşılaşacağınız bir problemdir.",[69,166],{},[72,168,170],{"id":169},"çözüm","Çözüm",[14,172,173,174,176,177,179],{},"Abstract Factory tasarım kalıbının ilk önerdiği çözüm, ürün ailesinin her bir ürün tipi için (koltuk, kanepe, sehpa gibi) ayrı bir arayüz (interface) oluşturmanızdır. Akabinde tüm varyantların bu arayüzü temel almasını sağlayabilirsiniz. Örneğin, tüm koltuk varyasyonlarında ",[102,175,104],{}," arayüzünü, tüm sehpa varyasyonlarında ise ",[102,178,111],{}," arayüzünü esas alabilirsiniz.",[14,181,182],{},[138,183],{"alt":184,"src":185},"The Chairs class hierarchy","\u002Fimages\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir\u002Fsolution1.avif",[14,187,188],{},[145,189,190],{},"Tüm varyantlar tek bir sınıf hiyerarşisine taşınmalıdır.",[14,192,193,194,197,198,201,202,205,206,209,210,213],{},"Bir sonraki adım, ürün ailesine ait olan ürünleri oluşturmak için gereken tüm metotları içeren bir arayüz, yani ",[18,195,196],{},"Abstract Factory Interface","'ini tanımlamaktır. Örneğin; ",[102,199,200],{},"createChair"," (koltuk oluştur), ",[102,203,204],{},"createSofa"," (kanepe oluştur), ",[102,207,208],{},"createCoffeeTable"," (sehpa oluştur) gibi. Bu metotlar, yukarıda tanımladığımız (koltuk, kanepe, sehpa) arayüz biçimlerinde ",[18,211,212],{},"soyut (abstract)"," ürünler döndürmelidir.",[14,215,216],{},[138,217],{"alt":218,"src":219},"The Factories class hierarchy","\u002Fimages\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir\u002Fsolution2.avif",[14,221,222],{},[145,223,224],{},"Her ürün varyantına özel Concrete Factory'ler",[14,226,227,228,231,232,235,236,239,240,243],{},"Ürün varyantları için bu Abstract Factory arayüzünü esas alan ayrı ayrı fabrika sınıfları (Factory Classes) oluşturmalıyız. Fabrika sınıfı, ilgili tipteki ürünü geri döndüren özel bir sınıftır. Örneğin ",[102,229,230],{},"ModernFurnitureFactory"," sınıfı sadece ",[102,233,234],{},"ModernChair",", ",[102,237,238],{},"ModernSofa"," ve ",[102,241,242],{},"ModernCoffeeTable"," nesnelerini döndürebilir.",[14,245,246],{},"İstemci kod, fabrikalar ve ürünlerle çalışırken her zaman ilgili soyut arayüzleri (interfaces) kullanmalıdır. Bu sayede, istemci koda parametre olarak gönderdiğiniz fabrika sınıfını ve ürün varyantını, asıl koda dokunmadan kolayca değiştirebilirsiniz.",[14,248,249],{},[138,250],{"alt":155,"src":251},"\u002Fimages\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir\u002Fabstract-factory-karikatur-2.avif",[14,253,254],{},[145,255,256],{},"Müşteri fabrikanın içinde dönen işleri bilmek zorunda olmadan sadece ürününü almalıdır.",[14,258,259,260,263,264,267],{},"Farz edelim istemci geldi ve fabrika sınıfımızdan bir koltuk istedi. İstemci, fabrikanın alt sınıfı veya arka planda nasıl bir koltuk üretildiği ile ilgilenmez. Abstract Factory arayüzüne uygun bir fabrika nesnesi kendisine verildiyse onun için yeterlidir. Böylece modern koltuk mu gelmiş, yoksa Viktorya tarzı mı gelmiş bunu umursamadan, üzerine oturmak için bir ",[102,261,262],{},"sitOn"," metodu içeren ",[102,265,266],{},"Chair"," arayüzüne uygun bir koltuk nesnesi alacağı garantidir. Dönen koltuğun varyantı neyse, gelecek kanepe ve sehpa gibi diğer ürünlerin varyantının da o olacağı bu sayede garanti altına alınmış olur.",[269,270,272],"h3",{"id":271},"abstract-factory-ve-factory-method-desenleri-arasındaki-fark","Abstract Factory ve Factory Method Desenleri Arasındaki Fark",[274,275,276,292],"table",{},[277,278,279],"thead",{},[280,281,282,287,290],"tr",{},[283,284,286],"th",{"align":285},"left","Özellik",[283,288,289],{"align":285},"Factory Method",[283,291,81],{"align":285},[293,294,295,309,322],"tbody",{},[280,296,297,303,306],{},[298,299,300],"td",{"align":285},[18,301,302],{},"Temel Odak",[298,304,305],{"align":285},"Tek bir ürünün oluşturulmasını alt sınıflara delege eder (Metot seviyesinde).",[298,307,308],{"align":285},"Birbiriyle ilişkili ürün ailelerinin oluşturulmasını sağlar (Sınıf seviyesinde).",[280,310,311,316,319],{},[298,312,313],{"align":285},[18,314,315],{},"Uygulama Yöntemi",[298,317,318],{"align":285},"Kalıtım (Inheritance) esaslıdır; alt sınıflar metodu ezerek nesneyi oluşturur.",[298,320,321],{"align":285},"Kompozisyon (Composition) esaslıdır; fabrika nesnesi bağlama enjekte edilir.",[280,323,324,329,332],{},[298,325,326],{"align":285},[18,327,328],{},"Gereksinim",[298,330,331],{"align":285},"Tek bir ürün üretilmek istendiğinde tercih edilir.",[298,333,334],{"align":285},"Birbiriyle uyumlu çalışması gereken birden fazla ürün grubu (örneğin Koltuk + Masa + Sehpa) olduğunda tercih edilir.",[69,336],{},[269,338,340],{"id":339},"uygulanabilirlik","Uygulanabilirlik",[14,342,343],{},[18,344,345],{},"Abstract Factory'ler, kodunuzun ilişkili ürünler içeren ürün aileleri ile çalışması gerektiği, fakat bu sınıfların somut içeriklerine bağımlı olmak istemediğiniz durumlarda size yardımcı olurlar. Bu sınıfların ne olacağı başlangıçta belirsiz olabilir veya belli olsa bile gelecekte programınızı daha kolay genişletmek isteyebilirsiniz.",[14,347,348],{},"Abstract Factory'ler ürün ailesinin üyelerini oluşturabileceğiniz soyut bir arayüz sunarlar. Kodunuz nesneleri bu arayüz üzerinden oluşturduğu sürece, üretilen diğer ürünlerle uyuşmayan, uyumsuz bir ürün varyasyonu üretilmesini engellemiş olursunuz.",[14,350,351],{},"İyi tasarlanmış bir sistemde her sınıfın tek bir sorumluluğu olmalıdır (Single Responsibility Principle). Eğer birden fazla işlevi idare eden karmaşık bir sınıfınız varsa, bunun fabrika metotlarını bağımsız fabrika sınıflarına (Factory Classes) veya tam bir Abstract Factory uygulamasına dönüştürmeniz faydalı olacaktır. Eğer kodunuzda bir Factory Method'a ihtiyaç duyuyorsanız, şimdi veya gelecekte benzer başka fabrika metotlarına ihtiyaç duyup duymayacağınızı değerlendirerek Abstract Factory yapısına geçişi planlayabilirsiniz.",[69,353],{},[72,355,357],{"id":356},"diğer-tasarım-desenleri-ile-i̇lişkisi","Diğer Tasarım Desenleri ile İlişkisi",[22,359,360,369,375,382,389],{},[25,361,362,363,365,366,368],{},"Birçok tasarım süreci ",[18,364,289],{}," kullanılarak başlar (daha az karmaşık olduğu ve alt sınıflarla özelleştirilebildiği için) ve ihtiyaçlar arttıkça ",[18,367,81],{}," yapısına doğru evrilir.",[25,370,371,374],{},[18,372,373],{},"Builder"," deseni kompleks nesnelerin adım adım oluşturulmasını sağlar. Abstract Factory ise ilgili nesne ailelerini tek seferde oluşturmak için idealdir. Abstract Factory ürünü hemen döndürürken, Builder ürünü istemciye teslim etmeden önce çeşitli yapılandırma adımları çalıştırmanıza izin verir.",[25,376,377,378,381],{},"Abstract Factory sınıfları genel olarak bir dizi Factory Method'dan oluşur, fakat bu sınıfları oluşturmak için ",[18,379,380],{},"Prototype"," kalıbını da tercih edebilirsiniz.",[25,383,384,385,388],{},"Abstract Factory kalıbını ",[18,386,387],{},"Bridge"," ile birlikte kullanabilirsiniz. Bu yöntem, Bridge üzerinde tanımlanan bazı soyutlamaların sadece belirli platformlar veya uygulamalarla çalışması gerektiğinde oldukça faydalıdır. Abstract Factory deseni bu ilişkileri kapsülleyerek karmaşıklığı ortadan kaldırır.",[25,390,391,392,395],{},"Abstract Factory sınıfları genellikle ",[18,393,394],{},"Singleton"," olarak tasarlanır.",[69,397],{},[72,399,401],{"id":400},"abstract-factory-kod-örnekleri","Abstract Factory Kod Örnekleri",[269,403,405],{"id":404},"örnek-php-kodu","Örnek PHP Kodu",[407,408,412],"pre",{"className":409,"code":410,"language":411,"meta":155,"style":155},"language-php shiki shiki-themes github-light github-dark","\u003C?php\n\nnamespace RefactoringGuru\\AbstractFactory\\Conceptual;\n\n\u002F**\n * The Abstract Factory interface declares a set of methods that return\n * different abstract products. These products are called a family and are\n * related by a high-level theme or concept. Products of one family are usually\n * able to collaborate among themselves. A family of products may have several\n * variants, but the products of one variant are incompatible with products of\n * another.\n *\u002F\ninterface AbstractFactory\n{\n    public function createProductA(): AbstractProductA;\n\n    public function createProductB(): AbstractProductB;\n}\n\n\u002F**\n * Concrete Factories produce a family of products that belong to a single\n * variant. The factory guarantees that resulting products are compatible. Note\n * that signatures of the Concrete Factory's methods return an abstract product,\n * while inside the method a concrete product is instantiated.\n *\u002F\nclass ConcreteFactory1 implements AbstractFactory\n{\n    public function createProductA(): AbstractProductA\n    {\n        return new ConcreteProductA1();\n    }\n\n    public function createProductB(): AbstractProductB\n    {\n        return new ConcreteProductB1();\n    }\n}\n\n\u002F**\n * Each Concrete Factory has a corresponding product variant.\n *\u002F\nclass ConcreteFactory2 implements AbstractFactory\n{\n    public function createProductA(): AbstractProductA\n    {\n        return new ConcreteProductA2();\n    }\n\n    public function createProductB(): AbstractProductB\n    {\n        return new ConcreteProductB2();\n    }\n}\n\n\u002F**\n * Each distinct product of a product family should have a base interface. All\n * variants of the product must implement this interface.\n *\u002F\ninterface AbstractProductA\n{\n    public function usefulFunctionA(): string;\n}\n\n\u002F**\n * Concrete Products are created by corresponding Concrete Factories.\n *\u002F\nclass ConcreteProductA1 implements AbstractProductA\n{\n    public function usefulFunctionA(): string\n    {\n        return \"The result of the product A1.\";\n    }\n}\n\nclass ConcreteProductA2 implements AbstractProductA\n{\n    public function usefulFunctionA(): string\n    {\n        return \"The result of the product A2.\";\n    }\n}\n\n\u002F**\n * Here's the the base interface of another product. All products can interact\n * with each other, but proper interaction is possible only between products of\n * the same concrete variant.\n *\u002F\ninterface AbstractProductB\n{\n    \u002F**\n     * Product B is able to do its own thing...\n     *\u002F\n    public function usefulFunctionB(): string;\n\n    \u002F**\n     * ...but it also can collaborate with the ProductA.\n     *\n     * The Abstract Factory makes sure that all products it creates are of the\n     * same variant and thus, compatible.\n     *\u002F\n    public function anotherUsefulFunctionB(AbstractProductA $collaborator): string;\n}\n\n\u002F**\n * Concrete Products are created by corresponding Concrete Factories.\n *\u002F\nclass ConcreteProductB1 implements AbstractProductB\n{\n    public function usefulFunctionB(): string\n    {\n        return \"The result of the product B1.\";\n    }\n\n    \u002F**\n     * The variant, Product B1, is only able to work correctly with the variant,\n     * Product A1. Nevertheless, it accepts any instance of AbstractProductA as\n     * an argument.\n     *\u002F\n    public function anotherUsefulFunctionB(AbstractProductA $collaborator): string\n    {\n        $result = $collaborator->usefulFunctionA();\n\n        return \"The result of the B1 collaborating with the ({$result})\";\n    }\n}\n\nclass ConcreteProductB2 implements AbstractProductB\n{\n    public function usefulFunctionB(): string\n    {\n        return \"The result of the product B2.\";\n    }\n\n    \u002F**\n     * The variant, Product B2, is only able to work correctly with the variant,\n     * Product A2. Nevertheless, it accepts any instance of AbstractProductA as\n     * an argument.\n     *\u002F\n    public function anotherUsefulFunctionB(AbstractProductA $collaborator): string\n    {\n        $result = $collaborator->usefulFunctionA();\n\n        return \"The result of the B2 collaborating with the ({$result})\";\n    }\n}\n\n\u002F**\n * The client code works with factories and products only through abstract\n * types: AbstractFactory and AbstractProduct. This lets you pass any factory or\n * product subclass to the client code without breaking it.\n *\u002F\nfunction clientCode(AbstractFactory $factory)\n{\n    $productA = $factory->createProductA();\n    $productB = $factory->createProductB();\n\n    echo $productB->usefulFunctionB() . \"\\n\";\n    echo $productB->anotherUsefulFunctionB($productA) . \"\\n\";\n}\n\n\u002F**\n * The client code can work with any concrete factory class.\n *\u002F\necho \"Client: Testing client code with the first factory type:\\n\";\nclientCode(new ConcreteFactory1());\n\necho \"\\n\";\n\necho \"Client: Testing the same client code with the second factory type:\\n\";\nclientCode(new ConcreteFactory2());\n","php",[102,413,414,422,429,435,440,446,452,458,464,470,476,482,488,494,500,506,511,517,523,528,533,539,545,551,557,562,568,573,579,585,591,597,602,608,613,619,624,629,634,639,645,650,656,661,666,671,677,682,687,692,697,703,708,713,718,723,729,735,740,746,751,757,762,767,772,778,783,789,794,800,805,811,816,821,826,832,837,842,847,853,858,863,868,873,879,885,891,896,902,907,913,919,925,931,936,941,947,953,959,965,970,976,981,986,991,996,1001,1007,1012,1018,1023,1029,1034,1039,1044,1050,1056,1062,1067,1073,1078,1084,1089,1095,1100,1105,1110,1116,1121,1126,1131,1137,1142,1147,1152,1158,1164,1169,1174,1179,1184,1189,1194,1200,1205,1210,1215,1220,1226,1232,1238,1243,1249,1254,1260,1266,1271,1277,1283,1288,1293,1298,1304,1309,1315,1321,1326,1332,1337,1343],{"__ignoreMap":155},[415,416,419],"span",{"class":417,"line":418},"line",1,[415,420,421],{},"\u003C?php\n",[415,423,425],{"class":417,"line":424},2,[415,426,428],{"emptyLinePlaceholder":427},true,"\n",[415,430,432],{"class":417,"line":431},3,[415,433,434],{},"namespace RefactoringGuru\\AbstractFactory\\Conceptual;\n",[415,436,438],{"class":417,"line":437},4,[415,439,428],{"emptyLinePlaceholder":427},[415,441,443],{"class":417,"line":442},5,[415,444,445],{},"\u002F**\n",[415,447,449],{"class":417,"line":448},6,[415,450,451],{}," * The Abstract Factory interface declares a set of methods that return\n",[415,453,455],{"class":417,"line":454},7,[415,456,457],{}," * different abstract products. These products are called a family and are\n",[415,459,461],{"class":417,"line":460},8,[415,462,463],{}," * related by a high-level theme or concept. Products of one family are usually\n",[415,465,467],{"class":417,"line":466},9,[415,468,469],{}," * able to collaborate among themselves. A family of products may have several\n",[415,471,473],{"class":417,"line":472},10,[415,474,475],{}," * variants, but the products of one variant are incompatible with products of\n",[415,477,479],{"class":417,"line":478},11,[415,480,481],{}," * another.\n",[415,483,485],{"class":417,"line":484},12,[415,486,487],{}," *\u002F\n",[415,489,491],{"class":417,"line":490},13,[415,492,493],{},"interface AbstractFactory\n",[415,495,497],{"class":417,"line":496},14,[415,498,499],{},"{\n",[415,501,503],{"class":417,"line":502},15,[415,504,505],{},"    public function createProductA(): AbstractProductA;\n",[415,507,509],{"class":417,"line":508},16,[415,510,428],{"emptyLinePlaceholder":427},[415,512,514],{"class":417,"line":513},17,[415,515,516],{},"    public function createProductB(): AbstractProductB;\n",[415,518,520],{"class":417,"line":519},18,[415,521,522],{},"}\n",[415,524,526],{"class":417,"line":525},19,[415,527,428],{"emptyLinePlaceholder":427},[415,529,531],{"class":417,"line":530},20,[415,532,445],{},[415,534,536],{"class":417,"line":535},21,[415,537,538],{}," * Concrete Factories produce a family of products that belong to a single\n",[415,540,542],{"class":417,"line":541},22,[415,543,544],{}," * variant. The factory guarantees that resulting products are compatible. Note\n",[415,546,548],{"class":417,"line":547},23,[415,549,550],{}," * that signatures of the Concrete Factory's methods return an abstract product,\n",[415,552,554],{"class":417,"line":553},24,[415,555,556],{}," * while inside the method a concrete product is instantiated.\n",[415,558,560],{"class":417,"line":559},25,[415,561,487],{},[415,563,565],{"class":417,"line":564},26,[415,566,567],{},"class ConcreteFactory1 implements AbstractFactory\n",[415,569,571],{"class":417,"line":570},27,[415,572,499],{},[415,574,576],{"class":417,"line":575},28,[415,577,578],{},"    public function createProductA(): AbstractProductA\n",[415,580,582],{"class":417,"line":581},29,[415,583,584],{},"    {\n",[415,586,588],{"class":417,"line":587},30,[415,589,590],{},"        return new ConcreteProductA1();\n",[415,592,594],{"class":417,"line":593},31,[415,595,596],{},"    }\n",[415,598,600],{"class":417,"line":599},32,[415,601,428],{"emptyLinePlaceholder":427},[415,603,605],{"class":417,"line":604},33,[415,606,607],{},"    public function createProductB(): AbstractProductB\n",[415,609,611],{"class":417,"line":610},34,[415,612,584],{},[415,614,616],{"class":417,"line":615},35,[415,617,618],{},"        return new ConcreteProductB1();\n",[415,620,622],{"class":417,"line":621},36,[415,623,596],{},[415,625,627],{"class":417,"line":626},37,[415,628,522],{},[415,630,632],{"class":417,"line":631},38,[415,633,428],{"emptyLinePlaceholder":427},[415,635,637],{"class":417,"line":636},39,[415,638,445],{},[415,640,642],{"class":417,"line":641},40,[415,643,644],{}," * Each Concrete Factory has a corresponding product variant.\n",[415,646,648],{"class":417,"line":647},41,[415,649,487],{},[415,651,653],{"class":417,"line":652},42,[415,654,655],{},"class ConcreteFactory2 implements AbstractFactory\n",[415,657,659],{"class":417,"line":658},43,[415,660,499],{},[415,662,664],{"class":417,"line":663},44,[415,665,578],{},[415,667,669],{"class":417,"line":668},45,[415,670,584],{},[415,672,674],{"class":417,"line":673},46,[415,675,676],{},"        return new ConcreteProductA2();\n",[415,678,680],{"class":417,"line":679},47,[415,681,596],{},[415,683,685],{"class":417,"line":684},48,[415,686,428],{"emptyLinePlaceholder":427},[415,688,690],{"class":417,"line":689},49,[415,691,607],{},[415,693,695],{"class":417,"line":694},50,[415,696,584],{},[415,698,700],{"class":417,"line":699},51,[415,701,702],{},"        return new ConcreteProductB2();\n",[415,704,706],{"class":417,"line":705},52,[415,707,596],{},[415,709,711],{"class":417,"line":710},53,[415,712,522],{},[415,714,716],{"class":417,"line":715},54,[415,717,428],{"emptyLinePlaceholder":427},[415,719,721],{"class":417,"line":720},55,[415,722,445],{},[415,724,726],{"class":417,"line":725},56,[415,727,728],{}," * Each distinct product of a product family should have a base interface. All\n",[415,730,732],{"class":417,"line":731},57,[415,733,734],{}," * variants of the product must implement this interface.\n",[415,736,738],{"class":417,"line":737},58,[415,739,487],{},[415,741,743],{"class":417,"line":742},59,[415,744,745],{},"interface AbstractProductA\n",[415,747,749],{"class":417,"line":748},60,[415,750,499],{},[415,752,754],{"class":417,"line":753},61,[415,755,756],{},"    public function usefulFunctionA(): string;\n",[415,758,760],{"class":417,"line":759},62,[415,761,522],{},[415,763,765],{"class":417,"line":764},63,[415,766,428],{"emptyLinePlaceholder":427},[415,768,770],{"class":417,"line":769},64,[415,771,445],{},[415,773,775],{"class":417,"line":774},65,[415,776,777],{}," * Concrete Products are created by corresponding Concrete Factories.\n",[415,779,781],{"class":417,"line":780},66,[415,782,487],{},[415,784,786],{"class":417,"line":785},67,[415,787,788],{},"class ConcreteProductA1 implements AbstractProductA\n",[415,790,792],{"class":417,"line":791},68,[415,793,499],{},[415,795,797],{"class":417,"line":796},69,[415,798,799],{},"    public function usefulFunctionA(): string\n",[415,801,803],{"class":417,"line":802},70,[415,804,584],{},[415,806,808],{"class":417,"line":807},71,[415,809,810],{},"        return \"The result of the product A1.\";\n",[415,812,814],{"class":417,"line":813},72,[415,815,596],{},[415,817,819],{"class":417,"line":818},73,[415,820,522],{},[415,822,824],{"class":417,"line":823},74,[415,825,428],{"emptyLinePlaceholder":427},[415,827,829],{"class":417,"line":828},75,[415,830,831],{},"class ConcreteProductA2 implements AbstractProductA\n",[415,833,835],{"class":417,"line":834},76,[415,836,499],{},[415,838,840],{"class":417,"line":839},77,[415,841,799],{},[415,843,845],{"class":417,"line":844},78,[415,846,584],{},[415,848,850],{"class":417,"line":849},79,[415,851,852],{},"        return \"The result of the product A2.\";\n",[415,854,856],{"class":417,"line":855},80,[415,857,596],{},[415,859,861],{"class":417,"line":860},81,[415,862,522],{},[415,864,866],{"class":417,"line":865},82,[415,867,428],{"emptyLinePlaceholder":427},[415,869,871],{"class":417,"line":870},83,[415,872,445],{},[415,874,876],{"class":417,"line":875},84,[415,877,878],{}," * Here's the the base interface of another product. All products can interact\n",[415,880,882],{"class":417,"line":881},85,[415,883,884],{}," * with each other, but proper interaction is possible only between products of\n",[415,886,888],{"class":417,"line":887},86,[415,889,890],{}," * the same concrete variant.\n",[415,892,894],{"class":417,"line":893},87,[415,895,487],{},[415,897,899],{"class":417,"line":898},88,[415,900,901],{},"interface AbstractProductB\n",[415,903,905],{"class":417,"line":904},89,[415,906,499],{},[415,908,910],{"class":417,"line":909},90,[415,911,912],{},"    \u002F**\n",[415,914,916],{"class":417,"line":915},91,[415,917,918],{},"     * Product B is able to do its own thing...\n",[415,920,922],{"class":417,"line":921},92,[415,923,924],{},"     *\u002F\n",[415,926,928],{"class":417,"line":927},93,[415,929,930],{},"    public function usefulFunctionB(): string;\n",[415,932,934],{"class":417,"line":933},94,[415,935,428],{"emptyLinePlaceholder":427},[415,937,939],{"class":417,"line":938},95,[415,940,912],{},[415,942,944],{"class":417,"line":943},96,[415,945,946],{},"     * ...but it also can collaborate with the ProductA.\n",[415,948,950],{"class":417,"line":949},97,[415,951,952],{},"     *\n",[415,954,956],{"class":417,"line":955},98,[415,957,958],{},"     * The Abstract Factory makes sure that all products it creates are of the\n",[415,960,962],{"class":417,"line":961},99,[415,963,964],{},"     * same variant and thus, compatible.\n",[415,966,968],{"class":417,"line":967},100,[415,969,924],{},[415,971,973],{"class":417,"line":972},101,[415,974,975],{},"    public function anotherUsefulFunctionB(AbstractProductA $collaborator): string;\n",[415,977,979],{"class":417,"line":978},102,[415,980,522],{},[415,982,984],{"class":417,"line":983},103,[415,985,428],{"emptyLinePlaceholder":427},[415,987,989],{"class":417,"line":988},104,[415,990,445],{},[415,992,994],{"class":417,"line":993},105,[415,995,777],{},[415,997,999],{"class":417,"line":998},106,[415,1000,487],{},[415,1002,1004],{"class":417,"line":1003},107,[415,1005,1006],{},"class ConcreteProductB1 implements AbstractProductB\n",[415,1008,1010],{"class":417,"line":1009},108,[415,1011,499],{},[415,1013,1015],{"class":417,"line":1014},109,[415,1016,1017],{},"    public function usefulFunctionB(): string\n",[415,1019,1021],{"class":417,"line":1020},110,[415,1022,584],{},[415,1024,1026],{"class":417,"line":1025},111,[415,1027,1028],{},"        return \"The result of the product B1.\";\n",[415,1030,1032],{"class":417,"line":1031},112,[415,1033,596],{},[415,1035,1037],{"class":417,"line":1036},113,[415,1038,428],{"emptyLinePlaceholder":427},[415,1040,1042],{"class":417,"line":1041},114,[415,1043,912],{},[415,1045,1047],{"class":417,"line":1046},115,[415,1048,1049],{},"     * The variant, Product B1, is only able to work correctly with the variant,\n",[415,1051,1053],{"class":417,"line":1052},116,[415,1054,1055],{},"     * Product A1. Nevertheless, it accepts any instance of AbstractProductA as\n",[415,1057,1059],{"class":417,"line":1058},117,[415,1060,1061],{},"     * an argument.\n",[415,1063,1065],{"class":417,"line":1064},118,[415,1066,924],{},[415,1068,1070],{"class":417,"line":1069},119,[415,1071,1072],{},"    public function anotherUsefulFunctionB(AbstractProductA $collaborator): string\n",[415,1074,1076],{"class":417,"line":1075},120,[415,1077,584],{},[415,1079,1081],{"class":417,"line":1080},121,[415,1082,1083],{},"        $result = $collaborator->usefulFunctionA();\n",[415,1085,1087],{"class":417,"line":1086},122,[415,1088,428],{"emptyLinePlaceholder":427},[415,1090,1092],{"class":417,"line":1091},123,[415,1093,1094],{},"        return \"The result of the B1 collaborating with the ({$result})\";\n",[415,1096,1098],{"class":417,"line":1097},124,[415,1099,596],{},[415,1101,1103],{"class":417,"line":1102},125,[415,1104,522],{},[415,1106,1108],{"class":417,"line":1107},126,[415,1109,428],{"emptyLinePlaceholder":427},[415,1111,1113],{"class":417,"line":1112},127,[415,1114,1115],{},"class ConcreteProductB2 implements AbstractProductB\n",[415,1117,1119],{"class":417,"line":1118},128,[415,1120,499],{},[415,1122,1124],{"class":417,"line":1123},129,[415,1125,1017],{},[415,1127,1129],{"class":417,"line":1128},130,[415,1130,584],{},[415,1132,1134],{"class":417,"line":1133},131,[415,1135,1136],{},"        return \"The result of the product B2.\";\n",[415,1138,1140],{"class":417,"line":1139},132,[415,1141,596],{},[415,1143,1145],{"class":417,"line":1144},133,[415,1146,428],{"emptyLinePlaceholder":427},[415,1148,1150],{"class":417,"line":1149},134,[415,1151,912],{},[415,1153,1155],{"class":417,"line":1154},135,[415,1156,1157],{},"     * The variant, Product B2, is only able to work correctly with the variant,\n",[415,1159,1161],{"class":417,"line":1160},136,[415,1162,1163],{},"     * Product A2. Nevertheless, it accepts any instance of AbstractProductA as\n",[415,1165,1167],{"class":417,"line":1166},137,[415,1168,1061],{},[415,1170,1172],{"class":417,"line":1171},138,[415,1173,924],{},[415,1175,1177],{"class":417,"line":1176},139,[415,1178,1072],{},[415,1180,1182],{"class":417,"line":1181},140,[415,1183,584],{},[415,1185,1187],{"class":417,"line":1186},141,[415,1188,1083],{},[415,1190,1192],{"class":417,"line":1191},142,[415,1193,428],{"emptyLinePlaceholder":427},[415,1195,1197],{"class":417,"line":1196},143,[415,1198,1199],{},"        return \"The result of the B2 collaborating with the ({$result})\";\n",[415,1201,1203],{"class":417,"line":1202},144,[415,1204,596],{},[415,1206,1208],{"class":417,"line":1207},145,[415,1209,522],{},[415,1211,1213],{"class":417,"line":1212},146,[415,1214,428],{"emptyLinePlaceholder":427},[415,1216,1218],{"class":417,"line":1217},147,[415,1219,445],{},[415,1221,1223],{"class":417,"line":1222},148,[415,1224,1225],{}," * The client code works with factories and products only through abstract\n",[415,1227,1229],{"class":417,"line":1228},149,[415,1230,1231],{}," * types: AbstractFactory and AbstractProduct. This lets you pass any factory or\n",[415,1233,1235],{"class":417,"line":1234},150,[415,1236,1237],{}," * product subclass to the client code without breaking it.\n",[415,1239,1241],{"class":417,"line":1240},151,[415,1242,487],{},[415,1244,1246],{"class":417,"line":1245},152,[415,1247,1248],{},"function clientCode(AbstractFactory $factory)\n",[415,1250,1252],{"class":417,"line":1251},153,[415,1253,499],{},[415,1255,1257],{"class":417,"line":1256},154,[415,1258,1259],{},"    $productA = $factory->createProductA();\n",[415,1261,1263],{"class":417,"line":1262},155,[415,1264,1265],{},"    $productB = $factory->createProductB();\n",[415,1267,1269],{"class":417,"line":1268},156,[415,1270,428],{"emptyLinePlaceholder":427},[415,1272,1274],{"class":417,"line":1273},157,[415,1275,1276],{},"    echo $productB->usefulFunctionB() . \"\\n\";\n",[415,1278,1280],{"class":417,"line":1279},158,[415,1281,1282],{},"    echo $productB->anotherUsefulFunctionB($productA) . \"\\n\";\n",[415,1284,1286],{"class":417,"line":1285},159,[415,1287,522],{},[415,1289,1291],{"class":417,"line":1290},160,[415,1292,428],{"emptyLinePlaceholder":427},[415,1294,1296],{"class":417,"line":1295},161,[415,1297,445],{},[415,1299,1301],{"class":417,"line":1300},162,[415,1302,1303],{}," * The client code can work with any concrete factory class.\n",[415,1305,1307],{"class":417,"line":1306},163,[415,1308,487],{},[415,1310,1312],{"class":417,"line":1311},164,[415,1313,1314],{},"echo \"Client: Testing client code with the first factory type:\\n\";\n",[415,1316,1318],{"class":417,"line":1317},165,[415,1319,1320],{},"clientCode(new ConcreteFactory1());\n",[415,1322,1324],{"class":417,"line":1323},166,[415,1325,428],{"emptyLinePlaceholder":427},[415,1327,1329],{"class":417,"line":1328},167,[415,1330,1331],{},"echo \"\\n\";\n",[415,1333,1335],{"class":417,"line":1334},168,[415,1336,428],{"emptyLinePlaceholder":427},[415,1338,1340],{"class":417,"line":1339},169,[415,1341,1342],{},"echo \"Client: Testing the same client code with the second factory type:\\n\";\n",[415,1344,1346],{"class":417,"line":1345},170,[415,1347,1348],{},"clientCode(new ConcreteFactory2());\n",[269,1350,1352],{"id":1351},"örnek-python-kodu","Örnek Python Kodu",[407,1354,1358],{"className":1355,"code":1356,"language":1357,"meta":155,"style":155},"language-python shiki shiki-themes github-light github-dark","from __future__ import annotations\nfrom abc import ABC, abstractmethod\n\nclass AbstractFactory(ABC):\n    \"\"\"\n    The Abstract Factory interface declares a set of methods that return\n    different abstract products. These products are called a family and are\n    related by a high-level theme or concept. Products of one family are usually\n    able to collaborate among themselves. A family of products may have several\n    variants, but the products of one variant are incompatible with products of\n    another.\n    \"\"\"\n    @abstractmethod\n    def create_product_a(self) -> AbstractProductA:\n        pass\n\n    @abstractmethod\n    def create_product_b(self) -> AbstractProductB:\n        pass\n\nclass ConcreteFactory1(AbstractFactory):\n    \"\"\"\n    Concrete Factories produce a family of products that belong to a single\n    variant. The factory guarantees that resulting products are compatible. Note\n    that signatures of the Concrete Factory's methods return an abstract\n    product, while inside the method a concrete product is instantiated.\n    \"\"\"\n\n    def create_product_a(self) -> AbstractProductA:\n        return ConcreteProductA1()\n\n    def create_product_b(self) -> AbstractProductB:\n        return ConcreteProductB1()\n\nclass ConcreteFactory2(AbstractFactory):\n    \"\"\"\n    Each Concrete Factory has a corresponding product variant.\n    \"\"\"\n\n    def create_product_a(self) -> AbstractProductA:\n        return ConcreteProductA2()\n\n    def create_product_b(self) -> AbstractProductB:\n        return ConcreteProductB2()\n\nclass AbstractProductA(ABC):\n    \"\"\"\n    Each distinct product of a product family should have a base interface. All\n    variants of the product must implement this interface.\n    \"\"\"\n\n    @abstractmethod\n    def useful_function_a(self) -> str:\n        pass\n\n\"\"\"\nConcrete Products are created by corresponding Concrete Factories.\n\"\"\"\n\nclass ConcreteProductA1(AbstractProductA):\n    def useful_function_a(self) -> str:\n        return \"The result of the product A1.\"\n\nclass ConcreteProductA2(AbstractProductA):\n    def useful_function_a(self) -> str:\n        return \"The result of the product A2.\"\n\nclass AbstractProductB(ABC):\n    \"\"\"\n    Here's the the base interface of another product. All products can interact\n    with each other, but proper interaction is possible only between products of\n    the same concrete variant.\n    \"\"\"\n    @abstractmethod\n    def useful_function_b(self) -> None:\n        \"\"\"\n        Product B is able to do its own thing...\n        \"\"\"\n        pass\n\n    @abstractmethod\n    def another_useful_function_b(self, collaborator: AbstractProductA) -> None:\n        \"\"\"\n        ...but it also can collaborate with the ProductA.\n\n        The Abstract Factory makes sure that all products it creates are of the\n        same variant and thus, compatible.\n        \"\"\"\n        pass\n\n\"\"\"\nConcrete Products are created by corresponding Concrete Factories.\n\"\"\"\n\nclass ConcreteProductB1(AbstractProductB):\n    def useful_function_b(self) -> str:\n        return \"The result of the product B1.\"\n\n    \"\"\"\n    The variant, Product B1, is only able to work correctly with the variant,\n    Product A1. Nevertheless, it accepts any instance of AbstractProductA as an\n    argument.\n    \"\"\"\n\n    def another_useful_function_b(self, collaborator: AbstractProductA) -> str:\n        result = collaborator.useful_function_a()\n        return f\"The result of the B1 collaborating with the ({result})\"\n\nclass ConcreteProductB2(AbstractProductB):\n    def useful_function_b(self) -> str:\n        return \"The result of the product B2.\"\n\n    def another_useful_function_b(self, collaborator: AbstractProductA):\n        \"\"\"\n        The variant, Product B2, is only able to work correctly with the\n        variant, Product A2. Nevertheless, it accepts any instance of\n        AbstractProductA as an argument.\n        \"\"\"\n        result = collaborator.useful_function_a()\n        return f\"The result of the B2 collaborating with the ({result})\"\n\ndef client_code(factory: AbstractFactory) -> None:\n    \"\"\"\n    The client code works with factories and products only through abstract\n    types: AbstractFactory and AbstractProduct. This lets you pass any factory\n    or product subclass to the client code without breaking it.\n    \"\"\"\n    product_a = factory.create_product_a()\n    product_b = factory.create_product_b()\n\n    print(f\"{product_b.useful_function_b()}\")\n    print(f\"{product_b.another_useful_function_b(product_a)}\", end=\"\")\n\n\"\"\"\nThe client code can work with any concrete factory class.\n\"\"\"\nif __name__ == \"__main__\":\n    print(\"Client: Testing client code with the first factory type:\")\n    client_code(ConcreteFactory1())\n\n    print(\"\\n\")\n\n    print(\"Client: Testing the same client code with the second factory type:\")\n    client_code(ConcreteFactory2())\n","python",[102,1359,1360,1365,1370,1374,1379,1384,1389,1394,1399,1404,1409,1414,1418,1423,1428,1433,1437,1441,1446,1450,1454,1459,1463,1468,1473,1478,1483,1487,1491,1495,1500,1504,1508,1513,1517,1522,1526,1531,1535,1539,1543,1548,1552,1556,1561,1565,1570,1574,1579,1584,1588,1592,1596,1601,1605,1609,1614,1619,1623,1627,1632,1636,1641,1645,1650,1654,1659,1663,1668,1672,1677,1682,1687,1691,1695,1700,1705,1710,1714,1718,1722,1726,1731,1735,1740,1744,1749,1754,1758,1762,1766,1770,1774,1778,1782,1787,1792,1797,1801,1805,1810,1815,1820,1824,1828,1833,1838,1843,1847,1852,1856,1861,1865,1870,1874,1879,1884,1889,1893,1897,1902,1906,1911,1915,1920,1925,1930,1934,1939,1944,1948,1953,1958,1962,1966,1971,1975,1980,1985,1990,1994,1999,2003,2008],{"__ignoreMap":155},[415,1361,1362],{"class":417,"line":418},[415,1363,1364],{},"from __future__ import annotations\n",[415,1366,1367],{"class":417,"line":424},[415,1368,1369],{},"from abc import ABC, abstractmethod\n",[415,1371,1372],{"class":417,"line":431},[415,1373,428],{"emptyLinePlaceholder":427},[415,1375,1376],{"class":417,"line":437},[415,1377,1378],{},"class AbstractFactory(ABC):\n",[415,1380,1381],{"class":417,"line":442},[415,1382,1383],{},"    \"\"\"\n",[415,1385,1386],{"class":417,"line":448},[415,1387,1388],{},"    The Abstract Factory interface declares a set of methods that return\n",[415,1390,1391],{"class":417,"line":454},[415,1392,1393],{},"    different abstract products. These products are called a family and are\n",[415,1395,1396],{"class":417,"line":460},[415,1397,1398],{},"    related by a high-level theme or concept. Products of one family are usually\n",[415,1400,1401],{"class":417,"line":466},[415,1402,1403],{},"    able to collaborate among themselves. A family of products may have several\n",[415,1405,1406],{"class":417,"line":472},[415,1407,1408],{},"    variants, but the products of one variant are incompatible with products of\n",[415,1410,1411],{"class":417,"line":478},[415,1412,1413],{},"    another.\n",[415,1415,1416],{"class":417,"line":484},[415,1417,1383],{},[415,1419,1420],{"class":417,"line":490},[415,1421,1422],{},"    @abstractmethod\n",[415,1424,1425],{"class":417,"line":496},[415,1426,1427],{},"    def create_product_a(self) -> AbstractProductA:\n",[415,1429,1430],{"class":417,"line":502},[415,1431,1432],{},"        pass\n",[415,1434,1435],{"class":417,"line":508},[415,1436,428],{"emptyLinePlaceholder":427},[415,1438,1439],{"class":417,"line":513},[415,1440,1422],{},[415,1442,1443],{"class":417,"line":519},[415,1444,1445],{},"    def create_product_b(self) -> AbstractProductB:\n",[415,1447,1448],{"class":417,"line":525},[415,1449,1432],{},[415,1451,1452],{"class":417,"line":530},[415,1453,428],{"emptyLinePlaceholder":427},[415,1455,1456],{"class":417,"line":535},[415,1457,1458],{},"class ConcreteFactory1(AbstractFactory):\n",[415,1460,1461],{"class":417,"line":541},[415,1462,1383],{},[415,1464,1465],{"class":417,"line":547},[415,1466,1467],{},"    Concrete Factories produce a family of products that belong to a single\n",[415,1469,1470],{"class":417,"line":553},[415,1471,1472],{},"    variant. The factory guarantees that resulting products are compatible. Note\n",[415,1474,1475],{"class":417,"line":559},[415,1476,1477],{},"    that signatures of the Concrete Factory's methods return an abstract\n",[415,1479,1480],{"class":417,"line":564},[415,1481,1482],{},"    product, while inside the method a concrete product is instantiated.\n",[415,1484,1485],{"class":417,"line":570},[415,1486,1383],{},[415,1488,1489],{"class":417,"line":575},[415,1490,428],{"emptyLinePlaceholder":427},[415,1492,1493],{"class":417,"line":581},[415,1494,1427],{},[415,1496,1497],{"class":417,"line":587},[415,1498,1499],{},"        return ConcreteProductA1()\n",[415,1501,1502],{"class":417,"line":593},[415,1503,428],{"emptyLinePlaceholder":427},[415,1505,1506],{"class":417,"line":599},[415,1507,1445],{},[415,1509,1510],{"class":417,"line":604},[415,1511,1512],{},"        return ConcreteProductB1()\n",[415,1514,1515],{"class":417,"line":610},[415,1516,428],{"emptyLinePlaceholder":427},[415,1518,1519],{"class":417,"line":615},[415,1520,1521],{},"class ConcreteFactory2(AbstractFactory):\n",[415,1523,1524],{"class":417,"line":621},[415,1525,1383],{},[415,1527,1528],{"class":417,"line":626},[415,1529,1530],{},"    Each Concrete Factory has a corresponding product variant.\n",[415,1532,1533],{"class":417,"line":631},[415,1534,1383],{},[415,1536,1537],{"class":417,"line":636},[415,1538,428],{"emptyLinePlaceholder":427},[415,1540,1541],{"class":417,"line":641},[415,1542,1427],{},[415,1544,1545],{"class":417,"line":647},[415,1546,1547],{},"        return ConcreteProductA2()\n",[415,1549,1550],{"class":417,"line":652},[415,1551,428],{"emptyLinePlaceholder":427},[415,1553,1554],{"class":417,"line":658},[415,1555,1445],{},[415,1557,1558],{"class":417,"line":663},[415,1559,1560],{},"        return ConcreteProductB2()\n",[415,1562,1563],{"class":417,"line":668},[415,1564,428],{"emptyLinePlaceholder":427},[415,1566,1567],{"class":417,"line":673},[415,1568,1569],{},"class AbstractProductA(ABC):\n",[415,1571,1572],{"class":417,"line":679},[415,1573,1383],{},[415,1575,1576],{"class":417,"line":684},[415,1577,1578],{},"    Each distinct product of a product family should have a base interface. All\n",[415,1580,1581],{"class":417,"line":689},[415,1582,1583],{},"    variants of the product must implement this interface.\n",[415,1585,1586],{"class":417,"line":694},[415,1587,1383],{},[415,1589,1590],{"class":417,"line":699},[415,1591,428],{"emptyLinePlaceholder":427},[415,1593,1594],{"class":417,"line":705},[415,1595,1422],{},[415,1597,1598],{"class":417,"line":710},[415,1599,1600],{},"    def useful_function_a(self) -> str:\n",[415,1602,1603],{"class":417,"line":715},[415,1604,1432],{},[415,1606,1607],{"class":417,"line":720},[415,1608,428],{"emptyLinePlaceholder":427},[415,1610,1611],{"class":417,"line":725},[415,1612,1613],{},"\"\"\"\n",[415,1615,1616],{"class":417,"line":731},[415,1617,1618],{},"Concrete Products are created by corresponding Concrete Factories.\n",[415,1620,1621],{"class":417,"line":737},[415,1622,1613],{},[415,1624,1625],{"class":417,"line":742},[415,1626,428],{"emptyLinePlaceholder":427},[415,1628,1629],{"class":417,"line":748},[415,1630,1631],{},"class ConcreteProductA1(AbstractProductA):\n",[415,1633,1634],{"class":417,"line":753},[415,1635,1600],{},[415,1637,1638],{"class":417,"line":759},[415,1639,1640],{},"        return \"The result of the product A1.\"\n",[415,1642,1643],{"class":417,"line":764},[415,1644,428],{"emptyLinePlaceholder":427},[415,1646,1647],{"class":417,"line":769},[415,1648,1649],{},"class ConcreteProductA2(AbstractProductA):\n",[415,1651,1652],{"class":417,"line":774},[415,1653,1600],{},[415,1655,1656],{"class":417,"line":780},[415,1657,1658],{},"        return \"The result of the product A2.\"\n",[415,1660,1661],{"class":417,"line":785},[415,1662,428],{"emptyLinePlaceholder":427},[415,1664,1665],{"class":417,"line":791},[415,1666,1667],{},"class AbstractProductB(ABC):\n",[415,1669,1670],{"class":417,"line":796},[415,1671,1383],{},[415,1673,1674],{"class":417,"line":802},[415,1675,1676],{},"    Here's the the base interface of another product. All products can interact\n",[415,1678,1679],{"class":417,"line":807},[415,1680,1681],{},"    with each other, but proper interaction is possible only between products of\n",[415,1683,1684],{"class":417,"line":813},[415,1685,1686],{},"    the same concrete variant.\n",[415,1688,1689],{"class":417,"line":818},[415,1690,1383],{},[415,1692,1693],{"class":417,"line":823},[415,1694,1422],{},[415,1696,1697],{"class":417,"line":828},[415,1698,1699],{},"    def useful_function_b(self) -> None:\n",[415,1701,1702],{"class":417,"line":834},[415,1703,1704],{},"        \"\"\"\n",[415,1706,1707],{"class":417,"line":839},[415,1708,1709],{},"        Product B is able to do its own thing...\n",[415,1711,1712],{"class":417,"line":844},[415,1713,1704],{},[415,1715,1716],{"class":417,"line":849},[415,1717,1432],{},[415,1719,1720],{"class":417,"line":855},[415,1721,428],{"emptyLinePlaceholder":427},[415,1723,1724],{"class":417,"line":860},[415,1725,1422],{},[415,1727,1728],{"class":417,"line":865},[415,1729,1730],{},"    def another_useful_function_b(self, collaborator: AbstractProductA) -> None:\n",[415,1732,1733],{"class":417,"line":870},[415,1734,1704],{},[415,1736,1737],{"class":417,"line":875},[415,1738,1739],{},"        ...but it also can collaborate with the ProductA.\n",[415,1741,1742],{"class":417,"line":881},[415,1743,428],{"emptyLinePlaceholder":427},[415,1745,1746],{"class":417,"line":887},[415,1747,1748],{},"        The Abstract Factory makes sure that all products it creates are of the\n",[415,1750,1751],{"class":417,"line":893},[415,1752,1753],{},"        same variant and thus, compatible.\n",[415,1755,1756],{"class":417,"line":898},[415,1757,1704],{},[415,1759,1760],{"class":417,"line":904},[415,1761,1432],{},[415,1763,1764],{"class":417,"line":909},[415,1765,428],{"emptyLinePlaceholder":427},[415,1767,1768],{"class":417,"line":915},[415,1769,1613],{},[415,1771,1772],{"class":417,"line":921},[415,1773,1618],{},[415,1775,1776],{"class":417,"line":927},[415,1777,1613],{},[415,1779,1780],{"class":417,"line":933},[415,1781,428],{"emptyLinePlaceholder":427},[415,1783,1784],{"class":417,"line":938},[415,1785,1786],{},"class ConcreteProductB1(AbstractProductB):\n",[415,1788,1789],{"class":417,"line":943},[415,1790,1791],{},"    def useful_function_b(self) -> str:\n",[415,1793,1794],{"class":417,"line":949},[415,1795,1796],{},"        return \"The result of the product B1.\"\n",[415,1798,1799],{"class":417,"line":955},[415,1800,428],{"emptyLinePlaceholder":427},[415,1802,1803],{"class":417,"line":961},[415,1804,1383],{},[415,1806,1807],{"class":417,"line":967},[415,1808,1809],{},"    The variant, Product B1, is only able to work correctly with the variant,\n",[415,1811,1812],{"class":417,"line":972},[415,1813,1814],{},"    Product A1. Nevertheless, it accepts any instance of AbstractProductA as an\n",[415,1816,1817],{"class":417,"line":978},[415,1818,1819],{},"    argument.\n",[415,1821,1822],{"class":417,"line":983},[415,1823,1383],{},[415,1825,1826],{"class":417,"line":988},[415,1827,428],{"emptyLinePlaceholder":427},[415,1829,1830],{"class":417,"line":993},[415,1831,1832],{},"    def another_useful_function_b(self, collaborator: AbstractProductA) -> str:\n",[415,1834,1835],{"class":417,"line":998},[415,1836,1837],{},"        result = collaborator.useful_function_a()\n",[415,1839,1840],{"class":417,"line":1003},[415,1841,1842],{},"        return f\"The result of the B1 collaborating with the ({result})\"\n",[415,1844,1845],{"class":417,"line":1009},[415,1846,428],{"emptyLinePlaceholder":427},[415,1848,1849],{"class":417,"line":1014},[415,1850,1851],{},"class ConcreteProductB2(AbstractProductB):\n",[415,1853,1854],{"class":417,"line":1020},[415,1855,1791],{},[415,1857,1858],{"class":417,"line":1025},[415,1859,1860],{},"        return \"The result of the product B2.\"\n",[415,1862,1863],{"class":417,"line":1031},[415,1864,428],{"emptyLinePlaceholder":427},[415,1866,1867],{"class":417,"line":1036},[415,1868,1869],{},"    def another_useful_function_b(self, collaborator: AbstractProductA):\n",[415,1871,1872],{"class":417,"line":1041},[415,1873,1704],{},[415,1875,1876],{"class":417,"line":1046},[415,1877,1878],{},"        The variant, Product B2, is only able to work correctly with the\n",[415,1880,1881],{"class":417,"line":1052},[415,1882,1883],{},"        variant, Product A2. Nevertheless, it accepts any instance of\n",[415,1885,1886],{"class":417,"line":1058},[415,1887,1888],{},"        AbstractProductA as an argument.\n",[415,1890,1891],{"class":417,"line":1064},[415,1892,1704],{},[415,1894,1895],{"class":417,"line":1069},[415,1896,1837],{},[415,1898,1899],{"class":417,"line":1075},[415,1900,1901],{},"        return f\"The result of the B2 collaborating with the ({result})\"\n",[415,1903,1904],{"class":417,"line":1080},[415,1905,428],{"emptyLinePlaceholder":427},[415,1907,1908],{"class":417,"line":1086},[415,1909,1910],{},"def client_code(factory: AbstractFactory) -> None:\n",[415,1912,1913],{"class":417,"line":1091},[415,1914,1383],{},[415,1916,1917],{"class":417,"line":1097},[415,1918,1919],{},"    The client code works with factories and products only through abstract\n",[415,1921,1922],{"class":417,"line":1102},[415,1923,1924],{},"    types: AbstractFactory and AbstractProduct. This lets you pass any factory\n",[415,1926,1927],{"class":417,"line":1107},[415,1928,1929],{},"    or product subclass to the client code without breaking it.\n",[415,1931,1932],{"class":417,"line":1112},[415,1933,1383],{},[415,1935,1936],{"class":417,"line":1118},[415,1937,1938],{},"    product_a = factory.create_product_a()\n",[415,1940,1941],{"class":417,"line":1123},[415,1942,1943],{},"    product_b = factory.create_product_b()\n",[415,1945,1946],{"class":417,"line":1128},[415,1947,428],{"emptyLinePlaceholder":427},[415,1949,1950],{"class":417,"line":1133},[415,1951,1952],{},"    print(f\"{product_b.useful_function_b()}\")\n",[415,1954,1955],{"class":417,"line":1139},[415,1956,1957],{},"    print(f\"{product_b.another_useful_function_b(product_a)}\", end=\"\")\n",[415,1959,1960],{"class":417,"line":1144},[415,1961,428],{"emptyLinePlaceholder":427},[415,1963,1964],{"class":417,"line":1149},[415,1965,1613],{},[415,1967,1968],{"class":417,"line":1154},[415,1969,1970],{},"The client code can work with any concrete factory class.\n",[415,1972,1973],{"class":417,"line":1160},[415,1974,1613],{},[415,1976,1977],{"class":417,"line":1166},[415,1978,1979],{},"if __name__ == \"__main__\":\n",[415,1981,1982],{"class":417,"line":1171},[415,1983,1984],{},"    print(\"Client: Testing client code with the first factory type:\")\n",[415,1986,1987],{"class":417,"line":1176},[415,1988,1989],{},"    client_code(ConcreteFactory1())\n",[415,1991,1992],{"class":417,"line":1181},[415,1993,428],{"emptyLinePlaceholder":427},[415,1995,1996],{"class":417,"line":1186},[415,1997,1998],{},"    print(\"\\n\")\n",[415,2000,2001],{"class":417,"line":1191},[415,2002,428],{"emptyLinePlaceholder":427},[415,2004,2005],{"class":417,"line":1196},[415,2006,2007],{},"    print(\"Client: Testing the same client code with the second factory type:\")\n",[415,2009,2010],{"class":417,"line":1202},[415,2011,2012],{},"    client_code(ConcreteFactory2())\n",[69,2014],{},[72,2016,2018],{"id":2017},"diğer-tasarım-kalıplarıdesign-patterns","Diğer Tasarım Kalıpları\u002FDesign Patterns",[14,2020,2021],{},[18,2022,2023],{},"Oluşumsal Kalıplar (Creational Patterns)",[14,2025,2026,2029,2030,2029,2033,2029,2036,2029,2039],{},[47,2027,289],{"href":2028},"\u002Ftr\u002Ftasarim-kaliplari-design-patterns-factory-method-nedir",",\n",[47,2031,81],{"href":2032},"\u002Ftr\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir",[47,2034,373],{"href":2035},"\u002Ftr\u002Fbuilder-tasarim-deseni-nedir",[47,2037,380],{"href":2038},"\u002Ftr\u002Fprototype-tasarim-deseni-nedir",[47,2040,394],{"href":2041},"\u002Ftr\u002Fsingleton-tasarim-deseni-nedir",[14,2043,2044],{},[18,2045,2046],{},"Yapısal Kalıplar (Structural Patterns)",[14,2048,2049,2029,2053,2029,2056,2029,2060,2029,2064,2029,2068,2029,2072],{},[47,2050,2052],{"href":2051},"\u002Ftr\u002Fadapter-tasarim-deseni-nedir","Adapter",[47,2054,387],{"href":2055},"\u002Ftr\u002Fbridge-tasarim-deseni-nedir",[47,2057,2059],{"href":2058},"\u002Ftr\u002Fcomposite-tasarim-deseni-nedir","Composite",[47,2061,2063],{"href":2062},"\u002Ftr\u002Fdecorator-tasarim-deseni-nedir","Decorator",[47,2065,2067],{"href":2066},"\u002Ftr\u002Ffacade-tasarim-deseni-nedir","Facade",[47,2069,2071],{"href":2070},"\u002Ftr\u002Fflyweight-tasarim-deseni-nedir","Flyweight",[47,2073,2075],{"href":2074},"\u002Ftr\u002Fproxy-tasarim-deseni-nedir","Proxy",[14,2077,2078],{},[18,2079,2080],{},"Davranışsal Kalıplar (Behavioral Patterns)",[14,2082,2083,2029,2087,2029,2091,2029,2095,2029,2099,2029,2103,2029,2107,2029,2111,2029,2115,2029,2119],{},[47,2084,2086],{"href":2085},"\u002Ftr\u002Fchain-of-responsibility-deseni-nedir","Chain of Responsibility",[47,2088,2090],{"href":2089},"\u002Ftr\u002Fcommand-tasarim-deseni-nedir","Command",[47,2092,2094],{"href":2093},"\u002Ftr\u002Fiterator-tasarim-deseni-nedir","Iterator",[47,2096,2098],{"href":2097},"\u002Ftr\u002Fmediator-tasarim-deseni-nedir","Mediator",[47,2100,2102],{"href":2101},"\u002Ftr\u002Fmemento-tasarim-deseni-nedir","Memento",[47,2104,2106],{"href":2105},"\u002Ftr\u002Fobserver-tasarim-deseni-nedir","Observer",[47,2108,2110],{"href":2109},"\u002Ftr\u002Fstate-tasarim-deseni-nedir","State",[47,2112,2114],{"href":2113},"\u002Ftr\u002Fstrategy-tasarim-deseni-nedir","Strategy",[47,2116,2118],{"href":2117},"\u002Ftr\u002Ftemplate-method-tasarim-deseni-nedir","Template Method",[47,2120,2122],{"href":2121},"\u002Ftr\u002Fvisitor-tasarim-deseni-nedir","Visitor",[2124,2125,2126],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":155,"searchDepth":424,"depth":424,"links":2128},[2129,2130,2131,2135,2136,2140],{"id":74,"depth":424,"text":75},{"id":87,"depth":424,"text":88},{"id":169,"depth":424,"text":170,"children":2132},[2133,2134],{"id":271,"depth":431,"text":272},{"id":339,"depth":431,"text":340},{"id":356,"depth":424,"text":357},{"id":400,"depth":424,"text":401,"children":2137},[2138,2139],{"id":404,"depth":431,"text":405},{"id":1351,"depth":431,"text":1352},{"id":2017,"depth":424,"text":2018},[2142],"technical",null,"2021-07-27","Bu yazı Design Patterns\u002FTasarım Desenleri nedir? başlıklı yazı dizisinin bir parçasıdır.",false,"md","\u002Fimages\u002Fposts\u002F2021\u002F07\u002Fabstract-factory-en1.avif",{},{"title":6,"description":2145},"tasarim-kaliplari-design-patterns-abstract-factory-nedir","tr\u002Ftasarim-kaliplari-design-patterns-abstract-factory-nedir",[2154,2155],"design-patterns","ipucu","zJpyQIFiNW0CTCq4d3Ra9M7bXdBW-lUprjmq5NoySwE",{"prev":2158,"next":2161,"others":2164,"lucky":2277,"readingTime":478},{"path":2159,"title":2160},"\u002Ftr\u002Ffactory-method-ve-abstract-factory-farki-nedir","Factory Method ve Abstract Factory Farkı Nedir?",{"path":2162,"title":2163},"\u002Ftr\u002Fapi-gateway-nedir","API Gateway Nedir? Ne İşe Yarar?",[2165,2168,2171,2173,2176,2179,2182,2184,2187,2190,2193,2196,2198,2201,2204,2207,2210,2213,2216,2219,2221,2224,2227,2230,2233,2236,2239,2242,2245,2248,2251,2253,2256,2259,2262,2264,2266,2269,2272,2275],{"path":2166,"title":2167},"\u002Ftr\u002Fgo-slice-veri-tipi","Go Veri Tipleri: Slice",{"path":2169,"title":2170},"\u002Ftr\u002Frestapi-ve-hateoas-kavrami","RestApi ve HATEOAS Kavramı",{"path":2062,"title":2172},"Decorator Tasarım Deseni Nedir?",{"path":2174,"title":2175},"\u002Ftr\u002Fes15-nedir-ecmascript-2024-nedir","ES15 nedir? ECMAScript 2024 nedir?",{"path":2177,"title":2178},"\u002Ftr\u002Fes14-nedir-ecmascript-2023-nedir","ES14 nedir? ECMAScript 2023 nedir?",{"path":2180,"title":2181},"\u002Ftr\u002Ftemiz-moduler-ve-yeniden-kullanilabilir-php-kodu-yazma-rehberi","PHP'de Temiz, Modüler ve Yeniden Kullanılabilir Kod Yazma Rehberi",{"path":2093,"title":2183},"Iterator Tasarım Deseni Nedir?",{"path":2185,"title":2186},"\u002Ftr\u002Ftricolor-garbage-collection-algoritmasi-nedir","Tricolor Garbage Collection Algoritması Nedir?",{"path":2188,"title":2189},"\u002Ftr\u002Fes12-nedir-ecmascript-2021-nedir","ES12 Nedir? ECMAScript 2021 Nedir?",{"path":2191,"title":2192},"\u002Ftr\u002Fubuntu-24-04-uzerinde-cyberpanel-kurulumu","Ubuntu 24.04 LTS ve 22.04 LTS Üzerinde CyberPanel Kurulumu",{"path":2194,"title":2195},"\u002Ftr\u002Fwordpress-yonetici-sifresini-wp-cli-kullanarak-sifirlama","WordPress Yönetici Şifresini WP-CLI Kullanarak Sıfırlama",{"path":2074,"title":2197},"Proxy Tasarım Deseni Nedir?",{"path":2199,"title":2200},"\u002Ftr\u002Fvite-nedir","Vite Nedir? Modern Web Geliştirme ve Paketleme Aracı",{"path":2202,"title":2203},"\u002Ftr\u002Fes13-nedir-ecmascript-2022-nedir","ES13 nedir? ECMAScript 2022 nedir?",{"path":2205,"title":2206},"\u002Ftr\u002Ffull-stack-proje-agaci","Full-Stack Proje Yol Haritası ve İçindekiler",{"path":2208,"title":2209},"\u002Ftr\u002Frest-api-dokumantasyonu-nasil-yapilir","REST Api Dokümantasyonu Nasıl Oluşturulur?",{"path":2211,"title":2212},"\u002Ftr\u002Fgo-ile-websockets-websocket-upgrader-nedir","Go ile WebSockets: Upgrader Nedir?",{"path":2214,"title":2215},"\u002Ftr\u002Ftailwind-css-nerede-kullanilir-tailwind-css-nerede-kullanilmaz","Tailwind CSS Nerede Kullanılır? Tailwind CSS Nerede Kullanılmaz?",{"path":2217,"title":2218},"\u002Ftr\u002Fphalcon-frameworkun-gelecegi","Phalcon Framework'ün Geleceği: Bir Devrin Sonu",{"path":2070,"title":2220},"Flyweight Tasarım Deseni Nedir?",{"path":2222,"title":2223},"\u002Ftr\u002Flitespeed-web-server-performans-artisi","Konfor Alanından Çıkıp, Konforlu Bir VPS'e Geçmek: LiteSpeed Web Server",{"path":2225,"title":2226},"\u002Ftr\u002Ffull-stack-proje-gelistiriyoruz","Full Stack Proje Geliştiriyoruz",{"path":2228,"title":2229},"\u002Ftr\u002Frest-api-tasarimi","REST API Tasarım İncelikleri",{"path":2231,"title":2232},"\u002Ftr\u002Fdigital-oceanda-vps-kurulumu","DigitalOcean'da VPS (Droplet) Kurulumu: Adım Adım Rehber",{"path":2234,"title":2235},"\u002Ftr\u002Fvue-3-hakkinda-bilmeniz-gerekenler-yenilikler","Vue 3 Hakkında Bilmeniz Gerekenler ve Yenilikler",{"path":2237,"title":2238},"\u002Ftr\u002Fopenlitespeed-ve-litespeed-enterprisei-reverse-proxy-olarak-kullanmak","OpenLiteSpeed ve LiteSpeed Enterprise Sunucularını Reverse Proxy Olarak Kullanmak",{"path":2240,"title":2241},"\u002Ftr\u002Fself-hosted-api-gateway-nasil-kurulur-kapsamli-rehber","Self-Hosted API Gateway Nasıl Kurulur? Kapsamlı Rehber",{"path":2243,"title":2244},"\u002Ftr\u002Fmerhaba-phalcon-framework","Merhaba Phalcon Framework",{"path":2246,"title":2247},"\u002Ftr\u002Fyeni-tema-honeywind","Yeni WordPress Temam Honeywind: Tailwind CSS ve Minimalizm",{"path":2249,"title":2250},"\u002Ftr\u002Fdocker-swarm-nedir","Docker Swarm Nedir?",{"path":2117,"title":2252},"Template Method Tasarım Deseni Nedir?",{"path":2254,"title":2255},"\u002Ftr\u002Fgo-veri-tipleri-map","Go Veri Tipleri - Map",{"path":2257,"title":2258},"\u002Ftr\u002Fphp-8-0-yenilikler","Merhaba PHP 8: Modern PHP 8.x Çağı",{"path":2260,"title":2261},"\u002Ftr\u002Fes7-nedir-ecmascript-2016-nedir","ES7 Nedir? ECMAScript 2016 Nedir?",{"path":2055,"title":2263},"Bridge Tasarım Deseni Nedir?",{"path":2051,"title":2265},"Adapter Tasarım Deseni Nedir?",{"path":2267,"title":2268},"\u002Ftr\u002Fubuntu-guncellemesi-sonrasi-cyberpanele-ulasilamama-sorunlarini-giderme","Ubuntu Güncellemesi Sonrası CyberPanel'e Ulaşılamama Sorunlarını Giderme",{"path":2270,"title":2271},"\u002Ftr\u002Fdocker-ve-portainer-kurulumu","Docker ve Portainer Kurulumu",{"path":2273,"title":2274},"\u002Ftr\u002Fubuntu-20-04-composer-kurulumu","Ubuntu 20.04 - Composer Kurulumu",{"path":2085,"title":2276},"Chain of Responsibility Deseni Nedir?",{"path":2278,"title":2279},"\u002Ftr\u002Fgo-ve-degiskenler","Go ve Değişkenler",[2281,2283,2286,2289],{"path":2051,"title":2265,"date":2282},"2021-08-21",{"path":2035,"title":2284,"date":2285},"Builder Tasarım Deseni Nedir?","2021-08-03",{"path":2028,"title":2287,"date":2288},"Factory Method Tasarım Deseni Nedir?","2021-07-24",{"path":2121,"title":2290,"date":2291},"Visitor Tasarım Deseni Nedir?","2021-10-09",[2293,2296,2298],{"path":2097,"title":2294,"date":2295},"Mediator Tasarım Deseni Nedir?","2021-10-03",{"path":2231,"title":2232,"date":2297},"2021-02-20",{"path":2214,"title":2215,"date":2299},"2021-09-25",1782142074278]