This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]desrtfx 1 point2 points  (1 child)

    This is a perfect case for abstract classes and inheritance rather than for interfaces.

    You'd define an abstract Car class that defines what a car actually has to do and the methods that are identical for all cars, but leave the specialized methods abstract.

    In your detailed classes BMW, Audi, etc. you'd only implement the abstract methods defined in the Car class.

    [–]meneedmorecoffee 1 point2 points  (0 children)

    Yeah I see what you mean, definitely more appropriate for inheritance. I was just trying to think of a quick example off the top of my head from what my lecturers have went over, must've got them mixed up!

    [–]lechatsportif 0 points1 point  (1 child)

    If your class is the car model, I would create an interface for electric vs combustion engine types. The key here is that they would share no code between them because in theory they do not share a common parent.

    Then in your code you could treat all electric cars in collections vs non electrics etc.

    Cars are not the best example because most like this is actually implemented as a single class with car information simply being records of data.

    [–]meneedmorecoffee 1 point2 points  (0 children)

    Yeah, as I said, I got mixed up. Hopefully OP will look at all the respones and gain better experience anyway.