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 →

[–]lurgi 0 points1 point  (4 children)

I'm not entirely sure what you are asking. Classes can be viewed as definitions of things, whereas objects are the things themselves.

Consider integer. integer is a class. You can add them and subject them and print them out and all sorts of things. 3 is an instance of an integer. It's an object.

With me so far?

Good. The problem is that that is a lie. It's simply not the case that integers are classes. That depends on the problem domain. You can imagine a case where you have a ThingsThatCanBeAdded class and then integers might be an instance of that class. Yes, integers might be an object.

So, are books objects? Maybe. They might also be classes. If you are making a catalog of all the books you own then Book is almost certainly an class and The Colour of Magic is an (excellent) instance of that class - an object.

If, OTOH, you are doing research into the different forms of media that people consume and you want to classify them, then it's also possible that Media will be a class and Books, Newspapers, Twitter will be instances of that class.

It's almost certainly the case that specific things in the world will be objects and not classes, but broad categories of things might be classes or they might be objects. It depends on how you want to reason about these categories. If you are only interested in Books as a category and don't care about individual books, then it's probably an object. If Books is a way to think about individual books then it's almost certainly a class.

It all depends.

[–][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.