I am a beginner in OOP. So far I found it very powerful. However, there is one concept, subclass & superclass, I do not understand very well. And do not know how to implement it but I am thinking I can utilize for my problem.
Could somebody explain to me with some example? What are the advantages?
Here is the problem I am dealing with. It is o describe objects in a room which contains many objects(child) like desks, tables, and other furniture. The room and the furniture have their own properties. I use a class for each of them as shown below. Calculations are to be done using the properties.
Some calculation to be done for subclass (child class like desk) needs to use properties of the superclass room. Some calculation to be done for superclass (child class like desk) needs to use properties of the subclass room.
So I am thinking the advantage of defining this type super/sub class relation is to help the reference to the properties of each other. What are other good applications. Otherwise, I can just define them as parallel class and include each other as input argument for function definitions. What difference does it, declaring super/subclass, make?
Thanks…
classdef room
properties
length
width
depth
end
end;
classdef desk < room
properties
size
color
weight
end
end
Best Answer