From: Bill Kelly Date: 2001-11-17T03:31:44+09:00 Subject: [ruby-talk:25572] Re: Something strange with Ruby's inheritance mechanism From: "Eric Jacoboni" > > >>>>> "Mathieu" == Mathieu Bouchard writes: > > Mathieu> In Ruby, A == B means it's _the_ same class, and A < B means > Mathieu> all objects that inherit from A also inherit from B, that is, > Mathieu> the set of A objects is smaller than the set of B objects. > > That's exactly my problem : A is a subset of B. A subset of objects: a > A object is always a B object, the opposite is not necessary true. My > first post was about the lack of this concept in Ruby: dynamic typing > prevents it as an A object may become, say, an Integer. As beginner in > Ruby, the surprise comes from the fact that the OOP is ok as long as > we stay at the class level but disappears when we come to instances > (object) because of dynamic typing. This trouble comes from my > experience with strong typing languages. As 'Eliza' might say, "Why do you think that the OOP is ok as long as we stay at the class level but disappears when we come to instances (object) because of dynamic typing?" :-) Not sure how to approach this but if you'll permit me to toss out a few bullet points: (and with all respect to Kristen Nygaard as the 'father of objects') . "Strong typing" means the type or class of an object can never change . "Weak typing" means the type/class of an object can be changed, such as by 'casting' . "Static typing" means a variable is bound to hold only a specific type/class of object at compile time . "Dynamic typing" means the type/class of an object held by a variable is determined at run-time . C++ (for instance) uses weak, static typing . Ruby and Smalltalk use strong, dynamic typing . Smalltalk is recognized as one of the most pure object-oriented languages . Smalltalk's inventor also coined the term "object-oriented" . Smalltalk's inventor is widely quoted as saying, "I invented the term Object-Oriented and I can tell you I did not have C++ in mind." So you see that there is a touch of humor involved in the suggestion that a dynamically typed language would somehow be less object-oriented than a statically typed one. If anything, according to the inventor of the term, it may be the other way around. :-) The confusion, if I may take a guess at it, may stem from those more familiar with static typing becoming used to somehow associating the type/class of an object, with the variable which may deign to accept an instance of that object, or not, based on some "type filter" or "type constraint" (in essence) bound with that variable at compile time. But that really has no relation to the type of the actual object, except by inference, (that is, in the sense that one may infer in a statically typed language, that the type of a variable must have some bearing on the type of object we expect that variable to point to.) Does that make sense? Hope this helps, Regards, Bill