Abstract Factory Pattern

실리콘·2023년 2월 15일
0

Intent

Provide an interface for creating families of related or dependent objects, w/o specifiying their concrete classes.

Also Known As

Kit

Motivation

To enable easy changing of the look, feel of an application. Also clients should stay independent of the prevailing look and feel. WidgetFactory is the topmost abstract class. There will be concrete subclass of WidgetFactory for each look-and-feel standard. ex. MotifWidgetFactory, which returns a Motif scroll bar. PMWidgetFactory, returning a scroll bar for Presentaion Manager.
Clients have no idea of WidgetFactory interface. Only use instance of the concrete subclasses, but adhere to interface defined by the abstract class WidgetFactory.

Applicability

  • A system should be independent of how its products are created, composed, and represented.
  • A system should be configured with one of multiple families of products.
  • A family of related product objects is designed to be used together, and you need to enforce this constraint.
  • You want to provide a class library of products, and want to reveal interfaces only, not implementation

Structure

Participants

  • AbstractFactory (WidgetFactory)
    - declares an interface for operations that create abstract product objects.
  • ConcreteFactory (MotifWidgetFactory, PMWidgetFactory)
    - implements the operations to create concrete product objects.
  • AbstractProduct (Window, ScrollBar)
    - declares an interface for a type of product object.
  • ConcreteProduct (MotifWindow, MotifScrollBar)
    - defines a product object to be created by the corresponding concrete factory.
    - implements the AbstractProduct interface.
  • Client
    - Only use interfaces defined by AbstratFactory and AbstractProduct

Collaborations

  • Normally a single instance of a ConcreteFactory class is created at run-time. Of course. its a factory. Creates one kind of product. If client wants different product, use another factory.
  • AbstractFactory defers creation of product objects to its ConcreteFactory subclass.

Consequences

Benefits & Liabilities
1. It isolates concrete classes. Product class names are isolated in the implementation of the concrete factory. not in client code.
2. It makes exchangin product families easy. The class of concrete factory appears only once in an application, where it's instantiated. So no duplicate code change when changin concrete factory to use.
3. Promotes consistency among products. AbstractFactory enforcement.
4. Supporting new kinds of products is difficult. Fixed interface. What if new product requires extended interface? hard. Lots of code to change. But one possible solution in Implementaion section.

Implementation

Some useful techniques for implementing the Abstrat Factory pattern.
1. Factories as singletons.
2. Creating the products. See Factory Method pattern for each product. This overrides I think the constructor() for product classes?
If many product families are possible, refer to Prototype pattern. A javascript like pattern I think.
Pure Prototype apporach
Concrete factory has protype of a product. Factory clones the prototype, and creates the product. Eliminates the need for a new concrete factory calss for each new product family.
Prototype variant
Possible in languages that treat classes as first-class objects. Define a new factory by initializing an instance of concrete factory with classes of products, not by subclassing. This approach takes advantage of language characteristics, whereas the pure Prototype-based approach is language-independent.
3. Defining extensible factories. AbstractFactory usually defines a different operation for each kind of product it can produce. The kinds of products are encoded in the operation signatures. Adding a new kind of product requires changin the AbstractFactory interface and all the classes that depend on it.

  • A more flexible, but less safe design is to add a parameter to operations that create objects. This parameter specified the kind of object to be created. Can be class identifier, integer, whatever. Then AbstractFactory would only need a single make() method with a parmeter indicating the kind of object to create. This is the technique used in the Prototype- and the class-based abstract factories discuessed earlier.
  • This variation is easier to use in a dynamically typed language (js, python).
  • A inherent problem: All products are returned to the client with the same abstract interface as given by the return type. The client will not be able to differentiate or mkae safe assumptions about the class of a product. If clients need to perform subclass-specific operations, they won't be accessible through the abstract interface. Could do a downcast, but not always feasible or safe, as downcast can fail. This is a classic trade-off for a highly flexible and extensible interface.

Sample Code

in C++ in books.
if you want dynamic language example, there is also SmallTalk example. But you have to know the C++ example first to understand.

Known Uses

Old cases.. Interviews? ET++?

implement using Factory Method, or Prototype
A concrete factory is often a Singleton.

profile
software engineer

54개의 댓글

comment-user-thumbnail
2024년 11월 16일

Great posting, moved in front plus saved as a favorite your web blog. I actually can’t put it off to read simple things extra out of you actually. Bijoux fabriqués au Québec

답글 달기
comment-user-thumbnail
2024년 11월 17일

It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks. how get my ip address

답글 달기
comment-user-thumbnail
2024년 11월 18일

I am definitely enjoying your website. You definitely have some great insight and great stories. bathroom rentals las vegas

답글 달기
comment-user-thumbnail
2024년 12월 9일

I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work.slot online

답글 달기
comment-user-thumbnail
2024년 12월 14일

With thanks to get furnishing recently available posts in connection with the dilemma, I actually look ahead to learn extra. 문자인증대행

답글 달기
comment-user-thumbnail
2024년 12월 15일

That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more. vviavi slot

답글 달기
comment-user-thumbnail
2024년 12월 22일

You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. nx303

답글 달기
comment-user-thumbnail
2024년 12월 30일

Good place, walked into the future together with bookmarked as their favorite your websites. That i can’t procrastinate to read the paper even more with everyone. 부산 출장마사지

답글 달기
comment-user-thumbnail
2024년 12월 31일

When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. slot777

답글 달기
comment-user-thumbnail
2025년 1월 4일

Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. situs togel

답글 달기
comment-user-thumbnail
2025년 1월 6일

Le code promo 1xBet 2025: 1XNEW25, saississez-le lors de votre inscription pour recevoir un bonus jusqu'à $130 sur le sport. Vous pourrez aussi obtenir jusqu'à $1,500 et 150 tours gratuits sur le casino. 1xBet propose jusqu'à $130 de freebets selon le montant de votre premier dépôt sur les paris sportifs. Parmi eux, le bonus de bienvenue, réservé aux nouveaux inscrits sur la plateforme. Cette plateforme est classée parmi les leaders en Afrique et à travers le monde. Elle vous offre les meilleures options pour vos paris, y compris la diffusion en direct des matchs sans frais supplémentaires. code promo 1xbet congo

답글 달기
comment-user-thumbnail
2025년 1월 14일

Don’t miss out on the 1win promo code MAX500WIN. Get a 500% bonus on your first four deposits, with rewards reaching up to $1025. New players can enjoy this lucrative offer today. Act now for the best benefits! 1win aviator promo code

답글 달기
comment-user-thumbnail
2025년 1월 14일

I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. www.hustlersuniversity.co

답글 달기
comment-user-thumbnail
2025년 1월 16일

This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… disposable vapes

답글 달기
comment-user-thumbnail
2025년 1월 18일

With the code 1X200BOX, 1xBet gives you a 130% bonus up to €130. Deposit, bet, and enjoy more chances to win big in 2025! meilleur code promo 1xbet

답글 달기
comment-user-thumbnail
2025년 1월 19일

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. situs slot terpercaya

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. slot online

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. situs toto alternatif

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. سایت پیش بینی لانا کازینو

답글 달기
comment-user-thumbnail
2025년 1월 20일

Superior post, keep up with this exceptional work. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! olxtoto

답글 달기
comment-user-thumbnail
2025년 1월 23일

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! 카지노 임대

답글 달기
comment-user-thumbnail
2025년 1월 23일

I love the way you write and share your niche! Very interesting and different! Keep it coming! 토토임대

답글 달기
comment-user-thumbnail
2025년 1월 28일

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. situs toto

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. toto togel

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. toto 4D

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. toto 4D

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. 청소년 토토사이트 추천

답글 달기
comment-user-thumbnail
2025년 1월 29일

You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. boutique musulmane en ligne

답글 달기
comment-user-thumbnail
2025년 1월 30일

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks burglar alarm repair near me

답글 달기
comment-user-thumbnail
2025년 1월 30일

I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... cctv installation company

답글 달기
comment-user-thumbnail
2025년 2월 1일

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. slot hoki asia

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. toto macau

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. situs toto

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends . hoki slot

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. Slot Gacor 777

답글 달기
comment-user-thumbnail
2025년 2월 1일

The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. hss auditor training

답글 달기
comment-user-thumbnail
2025년 2월 3일

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. prediksi bola parlay

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. 토토커뮤니티

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. 홈페이지 만들기

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. 토토커뮤니티

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. Ostéopathe Rezé femme enceinte

답글 달기
comment-user-thumbnail
2025년 2월 4일

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.除甲醛價格

답글 달기
comment-user-thumbnail
2025년 2월 6일

If you are looking for more information about flat rate locksmith Las Vegas check that right away. 爱思助手下载

답글 달기
comment-user-thumbnail
2025년 2월 10일

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. 안산 룸싸롱

답글 달기
comment-user-thumbnail
2025년 2월 10일

Most of the time I don’t make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post! Alexistogel

답글 달기
comment-user-thumbnail
2025년 2월 10일

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... 2025娛樂城

답글 달기
comment-user-thumbnail
2025년 2월 11일

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work daftar situs toto

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work 먹튀검증

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work 무료스포츠중계

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work 토토사이트추천

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work 토토사이트추천

답글 달기
comment-user-thumbnail
2025년 2월 12일

I read that Post and got it fine and informative. Link slot gacor thailand

답글 달기
comment-user-thumbnail
2025년 2월 12일

thank you for your interesting infomation. Minitoto

답글 달기
comment-user-thumbnail
2025년 2월 13일

Everything has its value. Thanks for sharing this informative information with us. GOOD works! paito warna hk

답글 달기
comment-user-thumbnail
2025년 2월 16일

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. GullyBet news updates

답글 달기
comment-user-thumbnail
2025년 2월 16일

I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! GullyBet promotions

답글 달기
comment-user-thumbnail
2025년 2월 19일

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. bandar toto macau https://www.ecuadorianfilmfest.com/

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. olxtoto daftar https://vubooo.com/

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. bandar togel https://mugsysrapsheet.com/

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. live draw sgp https://funnyking.io/

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. situs togel https://macperformance.com/

답글 달기
comment-user-thumbnail
2025년 2월 20일

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. olxtoto login

답글 달기
comment-user-thumbnail
2025년 2월 22일

Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. Imbaslot

답글 달기
comment-user-thumbnail
2025년 2월 22일

I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information. slot gacor

답글 달기
comment-user-thumbnail
2025년 2월 24일

Many thanks for that publish as well as excellent ideas.. actually We additionally believe that effort is actually the most crucial ingredient of obtaining achievement. Fitness Coach Casselberry FL

답글 달기
comment-user-thumbnail
2025년 2월 25일

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. situs slot

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. situs slot

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. situs toto slot

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. situs slot

I was surfing the Internet for information and came across your blog. I am impressed by the information you have o n this blog. It shows how well you understand this subject. sbobet

답글 달기
comment-user-thumbnail
2025년 2월 28일

Great posting, moved in front plus saved as a favorite your web blog. I actually can’t put it off to read simple things extra out of you actually.
서울웨딩박람회

답글 달기
comment-user-thumbnail
2025년 3월 3일

I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious...WOW Classic boost togel online agen togel toto togel

답글 달기
comment-user-thumbnail
2025년 3월 8일

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.. 대출사이트

답글 달기
comment-user-thumbnail
2025년 3월 10일

Thank you very much for this useful article. I like it.BHV cursus Utrecht

답글 달기
comment-user-thumbnail
2025년 3월 13일

The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.비대면 대출 사이트

답글 달기
comment-user-thumbnail
2025년 3월 25일

I am incapable of reading articles online very often, but I’m happy I did today. It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing. Satta king

답글 달기
comment-user-thumbnail
2025년 4월 8일

Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. bandar togel

Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. situs toto

Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. situs togel

Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. 대구 홈타이

Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. olxtoto macau

답글 달기
comment-user-thumbnail
2025년 4월 9일

A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. pestoto [olxtoto rtp](bandar togel) [https://www.zinzinzine.net/](bandar togel) [https://www.minalesliewujastyk.com/](data toto macau) https://www.stylusvinyl.com/

답글 달기
comment-user-thumbnail
2025년 4월 13일

A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post.olxtotoedctoto daftarrogtoto loginolxtoto loginslot gacoralexistogel login

답글 달기
comment-user-thumbnail
2025년 6월 14일

start to finish. Understanding the diverse palette of cannabis enthusiasts, we curate a vast selection ofchoice carts

답글 달기
comment-user-thumbnail
2025년 6월 14일

I have been impressed after read this because of some quality work and informative thoughts. I just want to say thanks for the writer and wish you all the best for coming! Your exuberance is refreshing.macau togel

답글 달기