The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Conan Elvitaro:
If there are common features that many implementing classes of an interface would need, then make an abstract class that implements your interface. An example for this design is java.util.List and java.util.AbstractList. With this approach clients of your API can still make their own interfaces which extend your interface. If you would only provide an abstract class that would not be possible. This is only one of many reasons why the strict "abstract class" approach is wrong. I don't see any exceptional situations where it would be good to have an abstract class that does not implement an interface.
There are also people who say that abstract classes should not be used at all.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
In the situation where you have full control over all clients of a class (that is, you aren't publishing an API to another team or something), an interface can easily be introduced when you need it - especially with todays powerfull refactoring tools.
Originally posted by Ilja Preuss:
In those situations, which I find to be most common, introducing an interface before you actually *need* one adds to the complexity of the code without giving you any benefits, or so it seems to me.
Originally posted by Ilja Preuss:
With what justification? Wouldn't that hold you from using such powerfull design patterns like Template Method or Factory Method?
...introducing an interface before you actually *need* one adds to the complexity of the code without giving you any benefits.
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
LOL!
Oh wait, I maintain code by people who think like that.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Conan Elvitaro:
it does not make much difference wether or not you are your own client
being the client of your own API does not justify the violation of fundamental OOD principles*.
The only difference is that the damage done by a poor design is not as high if you are your own client, because you can still change your interface (e. g. change a return type from an abstract class type to an interface type later). I agree that a broken design can easily be fixed with tools every developer has (usually the IDE in this case).
The fear of adding classes or interfaces is dangerous and has destroyed more than just one project. I do not see any negative impact when every type (declaration, return type, method parameter) is an interface type.
To provide a complete answer to the original question it seemed right to mention all serious opinions that are out there (that I know of). However, it is not my opinion and I can not justify it.
The principle violated here is "Program to an interface, not an implementation." If you use an abstract class (which naturally has some non-abstract methods, otherwise you would use an interface) as a type, you are programming to a particular implementation. All arguments that apply for this fundamental principle in general also apply in this case.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Tony Morris
Java Q&A (FAQ, Trivia)
Originally posted by Tony Morris:
No offence intended, mostly in jest. I apologise for the very obvious way it could have had another context applied.
In any case, I only just recently was told by a colleague to "reduce types because it simplifies the design", which kind of irked me a bit, because that is an elementary broken train of thought, and I have to deal with these kind of people far too often.
Without restating what is already very well documented, I refer you to the following: http://c2.com/cgi-bin/wiki?FearOfAddingClasses
You should also note that thinking in terms of "introducing an interface before you actually *need* one" is quite broken on another elementary level, but I suspect I'm putting my foot into a very low quality debate.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|