Give an example of a class and an example of an object. Describe what a class is, what an object is, and how they are related. Use your examples to illustrate the descriptions.
Your Discussion should be at least 250 words in length, but not more than 750 words.
Well, it depends on the language you are using; in pure object-oriented languages where everything is an object (like Smalltalk), classes are no exception and are also objects. In other languages, where classes are not considered first-class citizens, they are simply special language constructs or primitive types. From now on, I will use Smalltalk as the target language due to its support for reflection and consistent styling.
How are class methods only accessible by the name class.method? (internal working). Is this the same as object.method?
Since classes are objects, they in turn are instances of a class (metaclass). Thus, sending a message to a class is simply sending a message to an object whose role is to represent the behavior of the classes. There is a lot of literature, you can take a look, for example, here and here for acquaintance.
And if the class is the same as the object (belongs to the class of the object, which is the superclass of every thing in OO) and we instantiate it (make it an object), can we instantiate a class other than the class object.
I'm not sure if I'm following you here, but just to clarify that Object is not always the superclass of all classes. The point is, if you start tracking the relationship between classes and metaclasses, you might end up with a kind of infinite loop. This is handled differently in different languages, and, for example, in VisualWorks Smalltalk Object is a subclass of nil. The point is, nil is also an object (remember that everything is an object) and doesn't really represent anything. As you might expect, nil is an instance of the class (UndefinedObject) and also implements some of the class's protocols. As a result, it can be used to represent a class form in which nothing inherits :).
Comments
Leave a comment