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

posted Jan 26, 2012 16:22:17

0

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

posted Jan 26, 2012 16:31:44

0

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

posted Jan 26, 2012 16:46:03

0

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

posted Jan 26, 2012 16:57:49

0

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.

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.