Originally posted by Ricky Clarkson:
There is no good reason to write an abstract class.
Originally posted by Ricky Clarkson:
There is no good reason to write an abstract class. The typical reason is code reuse
Merrill
Consultant, Sima Solutions
Merrill
Consultant, Sima Solutions
Merrill
Consultant, Sima Solutions
The cost, however, is in complexity.
In your example, the signatures were simple with few parameters and no return types, but in the real world they may be more complex.
In a case where it is not anticipated that behavior will have to be changed at run-time, an abstract class is a simpler, and therefore better solution.
With an interface, it's easy to provide an alternative implementation, and it's easy to ensure that you haven't accidentally inherited any of your implementation from anywhere but java.lang.Object.
Merrill
Consultant, Sima Solutions
Rahul Bhattacharjee
LinkedIn - Blog
If you will look at your own code, you will see that it took over three times as many lines of code (38 compared to 11 not counting white space) in your builder example to accomplish the same thing the abstract example accomplished and it required the use of other artifacts that had to be built separately.
OO Programming style says that we should always visualise a problem/issue as a object model.
There are times, though, when one simply doesn't need that kind of flexibility.
I believe in the extreme programming principle of "build only what you need, and not what you think you might someday need".
If I'm dealing with a complex process, and I'm writing a new extension to that process, I don't want to have to think about how every detail works, and have to rebuild it all.
it's a good thing that I'm "accidentally inheriting" behavior, because I don't want to be in a situation where I have to remember and deal with every detail of the process.
I guess what I'm saying is that when you say "all Abstract classes are bad", you're taking on a tremendous burden of proof
As it happens, I already have the other artifacts ready in a library called functionalpeas.
That's the kind of thinking and good design that you'll never reach if an abstract class is your default, and you're happy with it.
Provide me some code that you think suits abstract classes, and I'll tell you why it doesn't.
all generalizations are bad
Prefer interfaces to abstract classes
Merrill
Consultant, Sima Solutions
While your pattern may be conceptually simple, and in a Utopian language may actually be simple, we're talking about Java.
Yes, I did scroll down to your other example, but don't accept it as a viable option since all coding standards that I must adhere to in my daily work don't allow public properties.
As it happens, I already have the other artifacts ready in a library called functionalpeas.
Wonderful for you, but I don't.
However, in Java, coding this pattern takes more effort than coding a simple abstract class.
While sweeping generalities like the ones you seem so fond of may be good for generating livelier forum discussions (and yours has certainly accomplished that goal!) They make for lousy policy, either personal or institutional.
Originally posted by Ricky Clarkson:
Really? You can write procedural code and comply with that, if you say that every procedure is an instance of a class.
Originally posted by Ricky Clarkson:
Human is a subclass of Omnivore, possibly indirectly via Mammal, etc. However, my ex-girlfriend, Jenny, is an instance of a subclass of Human (no offence meant to her), but is not an Omnivore. She is a Vegetarian.
Rahul Bhattacharjee
LinkedIn - Blog
And about the prodedure ,that again should be in object that its related to.
If OO paragdim doesn't say to visulaize a problem in terms to objects then what does OO advocates for ?
For the above , you are going to0 deep the inheretence tree.
Originally posted by Ricky Clarkson:
What if it relates to 2 objects? Or no objects?
Originally posted by Ricky Clarkson:
In more OO languages than Java, procedures are objects too. I think your book/lecturer tells you to visualise problems in terms of nouns, not objects in general. I suggest you read about the Kingdom of Nouns.
Originally posted by Ricky Clarkson:
You only say that because I pointed out a case that doesn't fit in the inheritance tree. If I'd said Human extends Omnivore extends Animal, and not mentioned Jenny, you'd probably be happy.
Rahul Bhattacharjee
LinkedIn - Blog
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |