aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Help understanding Abstract Factory from a factory Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Help understanding Abstract Factory from a factory Example" Watch "Help understanding Abstract Factory from a factory Example" New topic
Author

Help understanding Abstract Factory from a factory Example

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Suppose i have the following Factory example


I totally understand the factory but am confused with what an abstract factory would be like ?? Any example would be appreciated..
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187


All object factories above will be able to execute the hetso909Rule(). If this method should ever need to be modifed, it will only be modified in a single location.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Thanks for the example.. However a few questions
1)Why the need of a AbstractDog cant ConcreteDog impliment Dog ??
2)Why place an abstract with the interface isnt an interface itself abstract ??
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
1)Why the need of a AbstractDog cant ConcreteDog impliment Dog ??


This is only an example. As you might see, there are many different ways to design. In my example, there is a possibility that certain common behaviors might need to be implemented in the future. Having an AbstractDog class in the middle is good design and may turn out to be useful especially if there will be multiple ConcreteDog classes needed in the future. This example is designed upfront to support future changes with minimal impact, testing, etc.


2)Why place an abstract with the interface isnt an interface itself abstract ??

Why not?
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Thanks for clearing that up.. regarding the second question I just wanted to know if its possible to ommit the abstract keyword with the interface. Will it make any difference ? Thanks again for the great example
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You are welcome. Yes, the abstract keyword may be ommitted from the source code. The language designers were flexible. But, things are different inside the JVM and before compiling your class, the code signal for abstract will be added to the compiler input. Will it make any difference? Not one that a human can detect. However, always remember that an interface class ISA type of abstract class.
Radoslaw Maruszewski
Greenhorn

Joined: Jan 19, 2012
Posts: 1
Jimmy Clark wrote:You are welcome. Yes, the abstract keyword may be ommitted from the source code. The language designers were flexible. But, things are different inside the JVM and before compiling your class, the code signal for abstract will be added to the compiler input. Will it make any difference? Not one that a human can detect. However, always remember that an interface class ISA type of abstract class.


There's no real difference between "abstract interface" or "interface". I'd recommend to always use "interface", as it results in cleaner and more readable code.

Jimmy Clark wrote:Having an AbstractDog class in the middle is good design and may turn out to be useful especially if there will be multiple ConcreteDog classes needed in the future.


Creating scaffolding for classes that may be needed in the future is rarely a sign of a good design. Create what is needed now, and give yourself a possibility of extending this solution in the future. AbstractDog can be easily inserted to the class structure when necessary, so I'd postpone creation of this class until that time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help understanding Abstract Factory from a factory Example