Ready for a mind blowing philosophical OOP question?
I know that an object is supposed to be thought of as a SET of properties. I also know about inheritance, that child properties GENERALLY have the parent properties and method+ then some.
What I have been pondering is how/when to represent the REAL world in OOP form.
Yup, not a code code question, but the PHILOSOPHY BEHIND a best practice.
easy part first. I know that when something is contained by something else it is best represented by a property.
class passenger{}
class vehicle{
var passengers;
var driver;
}
class car extends vehicle{
}
I know (and detest) the basic tutorial example:
class animal{}
class rabbit extends animal{}
but it seems somewhat academic when trying to envision a real world relational system.
class pet extends animal {}
ok, then represent my pet rabbit??? represent my pet rabbit among wild rabbits?? represent my pet rabbit among wild rabbit being chased by pet dogs?
it also seems that you can build any working class hierarchy system up until YOU have to scale it
Again:
class animal{}
class rabbit extends animal{}
class pet extends rabbit {}
works until there other animals you want to have as pets
class animal{}
class pet extends animal{}
class rabbit extends pets {}
works until there you realize not ALL rabbits are pets.
so
class animal{}
class rabbit extends animal{
var $pet=flase;// default
function makePet($owner){
// now you have to set a property and create property that didn't exist before in the 'wild'
}
}
or
class animal{
var $specie;
}
class wild extends animal {
__construct($specie){}
}
class pet extends animal {
__construct($specie,$owner,$name ){}
}
this is fine until you need to domesticate a will animal into a pet.
In short, all hierarchical systems need a SET start and a SET end… so as to be able to determine whats should be a class and what should be a property.
Well I am sorry I have made a mess of all my examples above. Simply phrased my question is … what criteria does an experienced OOProgramer use to determine what is a child class, an independent class or a property so that his/her code is scalable?