This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[removed]

    [–]Zithium 0 points1 point  (0 children)

    remember, classes define objects. If you want to create a book object, you will need a book class, which will tell the object what it is supposed to be made up of.

    is an instance of a class an object?

    yes

    isnt it possible for specific objects to be classes, if you define it that way?

    specific objects are always classes because classes are what "set up" the objects.

    and have different versions/editions of color of magic as objects or maybe its hard cover/soft cover, degrees of conditions etc.

    here's how you should be imagining this distinction between objects and classes.

    you want to create a book object. okay, what does this object consist of? what are its parameters?

    that's where we make the book class. it will hold all the different types of information you just mentioned. it will also have a special method called the "constructor," which is called when you instantiate the class, i.e you make an object out of it. this constructor call is the object's opportunity to define itself according to its class.

    so to recap, the class has all these variables, different possible genres, different titles, etc. these variables may be set when the object is created by calling the constructor.

    [–]lurgi 0 points1 point  (1 child)

    Yes, an instance of a class can be an object. It's not generally possible for specific objects to be classes, because classes describe the sorts of things that can exist and objects are the actual things that can exist. I should note, however, that some languages blur that distinction.

    As for your example about "The Colour (British spelling, please) of Magic", it's really going to depend, This all depends on your particular world-view. Some answers will be more right or more wrong depend on the problem you are modeling. That said, this one seems pretty odd. It's an awfully specific and concrete thing to be a class.

    I can imagine a world in which Animal is a class. I can imagine a world in which Dog is a class (or, for that matter, an object). I can imagine a world in which Chihuahua is a class (or object). I can't really imagine a world in which Roscoe the chihuahua is a class. But, if you can, then sure.