Analysis of inheritence models

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Analysis of inheritence models

Post by alex.barylski »

I'm quite interested in the study of language, particularly programming languages. In studying inheritence in the context of language (not specific to programming models but any language) I have found myself asking some questions, which I'm hoping will shed more light on the subject for me and figured I would try asking a community to see the kind of replies I can get.

Remember this is a generic disscussion about inheritence, not bound to the exact laws of programming languages, so although multiple inheritence is not currently a part of my study, I am not convinced it should be shunned entirely as it is in the programming world (which really, like GOTO's...are only hazardess in inexperienced hands IMHO).

I'm not sure how to even start this disscussion, as details are all pretty vague as is my understanding. The desire to study such a model stems from the fact that, the best way to increase programmer productivity is to re-use code. One proven method for doing so, is inheritence and possibly composition, which for the sake of this disscussion, we shall assume are analogous to each other.

Again, I want to reiterate, that this is not bound to the same policies that make up good software design. So avoid the desire to draw on examples of good OOP practice if possible.

Here is essentially the problem I am faced with in conceptualizing my pusedo-langauge and it's inheritence model.

I have an object, which is derived from another object. The child object assumes everything of it's parent. Now assume there is a property in the parent which does not strictly apply to all or any children. Is it best to define that property as "private" in the parent class or indicate that it is not to be inherited inside the child class, as it's possible other children will want that property.

Can you foresee any design flaws (thinking abstract or generically) with supprting a bi-directional inheritence paradigm?

Inheritence, in the context of programming languages is typically dictated by the parent class. That is, if a property is set to "private" no derived children will inherit (directly) that property and any duplicate property defined/declared in the child class will simply exist without being any wiser that it was already defined in the parent class.

What is the purpose of this bi-directional model, you may ask? I'm not sure, just keeping my options open as this whole idea is still concept or abstract thinking on my behalf. In the application I plan on implementing this idea, I think could benefit from bi-directional inheritence, or maybe not. Thats what I'm trying to determine.

Programming languages support this functionality, sorta, with method overloading/overriding. If there is a function in a child class which you inherit but know you will never use or want, you can simply redeclare as private or override it and return NULL or similar technique. I am not dealing with functions so method overloading doesn't apply, which is why I have this question in regards to bi-directional inheritence.

I have also found myself asking the question about supprting what i would call deep inheritence. Consider the following example:

Code: Select all

Object A
Object B : Object A
Object C : Object B
With deep inheritence, Object B would inherit everything about it's parent and it's parent parent...expected results. What about the possibility to inherit everything of your parents and grand-parents, except for a property defined as "private" inside your parent's object, which also inherits from it's parent.

Here is the caveat. Property in Object A is inherited by property in Object B but declared as private, so...

Object C does not inherit property in Object B, however it does inherit the same property from Object A. Follow me?

Using a deep inheritence model when you derive Object C from B from A, Object C has all the same properties (updated and changed as required by each object in the hierarchy). However is Object B indicates it's property is private (no inheriting) then Object C would actually only inherit the property of Object A. This would allow some interesting (quite possibly chaotic inheritence trees).

Can you think of any design flaws which could potentially be introduced following this method of inheritence (thinking abstract not programmatically - remember same rules don't apply)?

If you think, I think to much! Then I think, your correct in thinking that. ;)

Seriously though, if this is of no interest to you and your not interested in thinking outside of the box and insist that current programming models have it right, then don't reply.

This is not a disscussion to discover new model of programming inheritence. I am simply observing generic inheritence models (could be programming objects, could be atoms, could be whatever, again abstract thinking) and would like the opinion of a few open minded individuals whom I know at least have an interest in how and why inheritence works the way it does.

Having started this disscussion with a biology prof. (many moons ago) yielded frustrating results, as to him, everything stemmed from a dual-parent inheritence, lineage is always that simple. Programming langauges (usually) dumb it down by allowing only a single parent inheritence model (except languages like C++ which allow multiple inheritence; 2 or more parents). I'm not sure what I am investigating, perhaps multiple inheritence or somethin more taboo, like incest. Where your brother is also you grand father. :D That was a joke, but the idea or possibility does apply.

p.s-I realize as developers we are programmed (no pun intended) to think a certain way about the world, so if you need to draw on programming examples to assist in explaining yourself, feel free. Such as hilighting potential problems in bi-directional inheritence models or the latter problem I have described. Just try and make it abstract. :)

Waiting for some interesting replies. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Analysis of inheritence models

Post by Christopher »

I have a really brilliant response to this but I can't give it because it does not assume that inheritance and composition are analogous it the way presented, it draws on examples of good OOP practice, and I think bi-directional inheritance is an oxymoron.

Darn.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Analysis of inheritence models

Post by alex.barylski »

arborint wrote:I have a really brilliant response to this but I can't give it because it does not assume that inheritance and composition are analogous it the way presented, it draws on examples of good OOP practice, and I think bi-directional inheritance is an oxymoron.

Darn.
Wow that means a lot of coming from you. :P

Your ability to think outside the box is outstanding. Truly remarkable. You must have the greatest minds banging down your door with an open mind like that?

What part of: "If this is beyond you or of no interest please don't reply" didn't you understand? I realize it's a free board and you are free to reply, but you explicitly went against my wishes, why? The *only* reason I can think of, is for the sake of confrontation. Trying to demonstrate your brilliance through your own ignorance. Which if you ask me, is the *real* oxymoron. ;)

While inheritance by definition suggests parent-child (predecessor-successor) relationships. Try looking at the objects from both perspectives (child and parent) in that either can take on the form of parent or child; hence bi-directional. Remember when I said think abstract?

Your terse yet ignorant (as in closed minded nothing against you as a person) response shows your true colors. It amazes me that you have managed to brainwash so many on here into thinking your the official DN patterns geek.

p.s-please do not reply. I would also like to request this topic be removed before it starts any further flame wars of he said she said.

Cheers :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

No ... I actually think I have some very interesting thoughts on this subject. But because you are the only member of the site who spells out in your posts specific rules on why others are not allowed to reply to your posts, I was unable to respond to OP.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

arborint wrote:No ... I actually think I have some very interesting thoughts on this subject. But because you are the only member of the site who spells out in your posts specific rules on why others are not allowed to reply to your posts, I was unable to respond to OP.
Ehhh...if you felt you had something to contribute, why didn't you? I'm all ears.

Perhaps I jumped the gun, but your initial reply sucked, no offence. The problem is, I often find you very unilateral in theoretical disscussions, and what I didn't want, was a disscussion on how OOP is the end all, be all of inheritence models. Multiple (dual parent) inheritence works in life, as we all stem from two parents, but fails in OOP. So clearly different inheritence models are effective under different situations. Because I am not even sure myself what it is I am seeking, I didn't want to put a concrete definition of what was acceptable or not. Knowing I was posting on a programming forum, I figured someone would draw a hardline, either associating or invalidating any claims I made with OOP practices, etc.

To suggest that my idea of bi-directional inheritence (perhaps incorrect terminology; but I found a PDF study on inheritence models and it used that term as well, so I borrowed it) is an oxymoron, when the disscussion is this vague (that couldn't be proven at this stage) is a sign of closed minded-ness. So, I am sorry if I came across as not willing to accept others opinions (quite the contrary) I just didn't want it to sway towards OOP practices and principles. Again, this is an abstract disscussion on inheritence, nothing concrete.

So, seeing as how no one else has replied and you feel you have something worthy to contribute (not trying to disprove anything as it is still unclear of what it is I am trying to prove or understand) by all means, I would love to hear your input.

If you are going to explain that bi-directional inheritence won't work (by nature of being a oxymoron) and then draw on a specific example using OOP. That is *not* what i am after. a theoretical disscussion on inheritence models, anything goes, like in art, there doesn't have to be a concrete answer.

Cheers :)
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Re: Analysis of inheritence models

Post by stereofrog »

Hockey wrote: I have an object, which is derived from another object. The child object assumes everything of it's parent. Now assume there is a property in the parent which does not strictly apply to all or any children. Is it best to define that property as "private" in the parent class or indicate that it is not to be inherited inside the child class, as it's possible other children will want that property.
Something like this was once proposed for ruby, in regard to traits/mixins.

Code: Select all

class Bird
   include CanFly   # CanFly behaviour, common for Birds, Flies etc
   include LaysEggs # LaysEggs behaviour, common for Birds, Fishes etc
   ....
   methods of bird
end

# Penguin is a Bird, but lacks CanFly behaviour

class Penguin < Bird
   uninclude  CanFly
end
Looks exciting, but the correct implementation would be too complicated, for example, what if mixins depend on each other: how can we uninstall a dependent mixin?
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Post by Selkirk »

You might consider another word for inheritance is classification. People have been developing general theories of classification for millennia. We generally lump these approaches into the discipline of philosophy.

If you are interested in the intersection between philosophy and OOP, I recommend the book "Business Objects" by Chris Partridge. However, what I found valuable about this book was that it convinced me to to abandon this line of inquiry as not leading to anything useful. Sadly, this was probably not the intention of the author of the book. I examined the same data from his argument and came to a different conclusion.

The problem is one of consistency. You want it, but you can never actually have it. Human minds just don't function that way. The more consistency your model of the world attains, the less able you are to actually grasp it and use it as a tool. When you ask if current programming models have things "right," there is no such thing as right, there are only good tools.

What I think is interesting is that more experienced OO programmers avoid inheritance and its rigid classification rules and favor composition.

If you are more interested in how human beings think and represent knowledge, specifically related to categorization, two books that you might find interesting are

Women, Fire, and Dangerous Things by George Lakoff
Everything is Miscellaneous by David Weinberger (on the book circuit now. Search YouTube for many talks on this book.)
ThePCNerd
Forum Newbie
Posts: 6
Joined: Wed Oct 13, 2004 10:38 pm

Post by ThePCNerd »

From what I understand you are saying that Object A has a property of the same name as Object B, but Object B's property is private, and thus would not pass through to Object C, well neither would Object A's because redefinition of a variable in Object A to private in Object B can't happen, at least in my limited knowledge of OOP.
Post Reply