Forums Register Login

Relationship between Class and Object

+Pie Number of slices to send: Send
Am I correct in saying that the relationship between Class and Object is the same as the relationship between a glass jar that you store things in? (Example: A glass jar(Class) that contains various berries(Objects))
+Pie Number of slices to send: Send
No, that does not sound right.

If you want to take an analogy, a class is like a cookie cutter and the objects are all the cookies made using that cookie cutter
+Pie Number of slices to send: Send
 

glass jar that you store things in


I meant to say, "glass jar and the things you store in it".

I can't edit the original post for some reason.
+Pie Number of slices to send: Send
Think of a class as a template. You can use this template to create several objects out of it.
+Pie Number of slices to send: Send
 

Luzie Blankenship wrote:I can't edit the original post for some reason.


Information on editing posts
https://coderanch.com/t/685738/edit-post

The short answer is when you get enough of a good reputation you can edit your posts.

By the way, welcome to CodeRanch.
+Pie Number of slices to send: Send
 

Luzie Blankenship wrote:a glass jar and the things you store in it? (Example: A glass jar(Class) that contains various berries(Objects))


By your analogy, it would be the same as an egg carton (class) and eggs (objects).

I can kind of see why you might think that given the way some classes are written but the analogy is not apropos.

The cutter:cookies and template:object analogies are better fits.  Another is that of blueprint to product. A class is like engineering drawings and specifications for building a car. Objects, of course, are the actual cars you build out of the plans. Another example: A class is like a floor plan for an apartment unit. Objects are the actual apartment units that are built based on the plan.

+Pie Number of slices to send: Send
 

Junilu Lacar wrote:. . . blueprint . . . for building a car. . . .

Which tells you things like where the engine goes, but omits information like colour of bodywork or chassis number. A class Car might have spaces in for colour or number, but wouldn't specify them directly.
Even less would the blueprints have such info as speed travelled, but that is an important feature of a car. But the class would have a space for speed.
Liar, liar, pants on fire! refreshing plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 387 times.
Similar Threads
can CMP be used...................
Sun qstns - "has a" relationship
Need Details (code examples for relationships)
When class casting should output runtime exception and when it should output compiler error
Difference between process and programs?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:50:44.