MHB Why Can Penguins Be Subtyped as Birds But Motorcycles Not as Cars in OOP?

  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Programming
AI Thread Summary
In object-oriented programming, the classification of a penguin as a subtype of bird is acceptable despite its differing attributes, such as the inability to fly, because it aligns with the concept of inheritance where a penguin is a specialized version of a bird. This reflects the principle of "is-a" relationships in which subtypes share a common base class. Conversely, a motorcycle cannot be classified as a subtype of a car because, despite both having similar behaviors like driving, a motorcycle does not fit the "is-a" relationship with cars. Instead, both motorcycles and cars are better categorized under a broader class, MotorizedVehicle, which accurately represents their shared characteristics without misrepresenting their distinct identities.
tmt1
Messages
230
Reaction score
0
For object oriented programming, why is is acceptable to have a
penguin be a subtype of bird even though a penguin has different
attributes than a bird(supposing we have a fly method) and yet it is
unacceptable for for Motorcycle to be a subtype of Car even though it
has the same behaviour (ie drive method)?
 
Technology news on Phys.org
tmt said:
For object oriented programming, why is is acceptable to have a
penguin be a subtype of bird even though a penguin has different
attributes than a bird(supposing we have a fly method) and yet it is
unacceptable for for Motorcycle to be a subtype of Car even though it
has the same behaviour (ie drive method)?

Hi tmt!

Both Car and Motorcycle are specializations of a MotorizedVehicle.
That's the one that has for instance a drive method.
Put otherwise, we can't say that a Motorcycle "is a" Car, since that is just not true.

On the other hand, we can treat a penguin as a more specialized version of a bird.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top