73
votes
13answers
6k views

Why would Square inheriting from Rectangle be problematic if we override the SetWidth and SetHeight methods?

If a Square is a type of Rectangle, than why can't a Square inherit from a Rectangle? Or why is it a bad design? I have heard people say: If you made Square derive from Rectangle, then a Square ...
2
votes
3answers
493 views

Empty virtual method on base class VS abstract methods

I couldn't find a question that was not too specific to some case, so I'll try to make this very generic. We need an extractor base class to a set of documents, for example. Each document has its ...
0
votes
1answer
116 views

Names for generic classes - how to avoid naming them just “object”? Use synonyms?

When programming, I often end up naming some generic class (think of an abstract base class for stuff you manage in your project) something like FooObject, FooComponent or FooItem (where Foo is an ...
4
votes
5answers
721 views

What is the name of this particular kind of over-engineering? [closed]

When faced with (even a small) project, I tend to fall into the following bad practice. I think about the structure of the problem. Then I create some base classes, derive from them and then derive ...
3
votes
1answer
491 views

Too complex/too many objects?

I know that this will be a difficult question to answer without context, but hopefully there are at least some good guidelines to share on this. The questions are at the bottom if you want to skip the ...
1
vote
3answers
229 views

Should I use an interface when methods are only similar?

I was posed with the idea of creating an object that checks if a point will collide with a line: public class PointAndLineSegmentCollisionDetector { public void Collides(Point p, LineSegment s) { ...
22
votes
17answers
2k views

What is the value in hiding the details through abstractions? Isn't there value in transparency?

Background I am not a big fan of abstraction. I will admit that one can benefit from adaptability, portability and re-usability of interfaces etc. There is real benefit there, and I don't wish to ...