• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Perfect Example of Abstract Factory Variant2 in java.nio.file.Paths ?

 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even tho Abstract Factory is one of the most core and central of the Design Patterns, I have seen no end of confusion about it.

I wanted to see if I could come up with a good example of what this site calls "Variant 2" or "Concrete Factory":
https://w3sdesign.com/
See "Implementation" (Variant 2) and "Sample Code" (Example 2)

I think I have one perfect one:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Paths.html

(Okay, not perfect, because this factory only creates exactly one kind of product, not a family of compatible ones to be used together.)

That site is one of my favorite of all the ones I researched for both the Links page and to refer people to when they seem confused about this sometimes confusing topics.

The one thing that several other sites cover that they don't is "Examples of each pattern from the JDK".

Most of the other sites have very confused ideas about at least one or another of the important patterns, so I can overlook this.




 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:(Okay, not perfect, because this factory only creates exactly one kind of product, not a family of compatible ones to be used together.)


What do you mean by this?
 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some people seem to feel that the Absolute Essence of "Abstract Factory" includes the notion of producing multiple products together in a family or compatible or matching objects/products.  (This is a family of one.)

Several of the better sources seem to feel this is an essential part of that Design Pattern, most of the ones that don't seem also to go off into left field on some of the other patterns.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The absolute essence of the abstract factory is that you don't know and don't care about the concrete type of the thing that the factory creates.

That includes not caring whether it's a family with only one member.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that it's not ever true that Paths creates only one type of object.

Path is implemented by different classes on different file systems. For instance, on my machine it returns sun.nio.fs.WindowsPath.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic