1
$\begingroup$

After a year hiatus from Computer Science courses in college, im back to hitting them hard for the next two years straight. In the next few weeks before classes start again I have been trying to refresh my memory on key concepts by writing and trying to explain them to people that have never gotten deeper into a computer than Word, or Excel, maybe even just Photoshop.

Right now i'm trying to explain Objects and Classes, using the cookie cutter is a class and a cookie is an object.

In trying to explain Objects I thought that starting with trying to describe a Cookie would be easy and I described it like so.

Dinosaur_Cookie_Name = "T-Rex"
Dinosaur_Cookie_Frosting_Colour = "Green" 
Dinosaur_Cookie_Eaten = False

And then I was going to explain how these have no linking between them and that if you wanted to say that

my_cookie = Dinosaur_Cookie_Name

it doesn't necessarily mean that it's also green and uneaten.

So I was then going to explain that by making my_cookie a list, you could then iterate through the list to access properties and tada, a sort of rudimentary object. Afterwards would then be, tada here is what an object is.

That's where I froze. In the year since learning about Objects in my beginning C++ class I couldn't remember how I made the jump TO Objects. I remember a little talk about name spaces and pointers but thats about it.

So do objects store properties in an array? Would it be appropriate in teaching about Objects to have a middle step of a list, between non-associated variables and an object?

$\endgroup$
  • 6
    $\begingroup$ I think you are mixing concepts and implementation issues in an unhelpful way. $\endgroup$ – Raphael Aug 14 '16 at 11:57
1
$\begingroup$

Car

My favourite explanation of objects/classes is centered at cars.


Class

Class is defined as a schematic of information you can "measure from" or "store in" a car instance. For example, every car has a color, production date, total distance passed, etc.


Object

Objects are "real" or "existant" things made upon a class (schematic). All the cars consist of properties such as color and distance traveled, but the actual values of these properties may vary.


Implementation

Object implementation may differ between languages and compilers, but I guess this might be a good way to do it:

Calculate space needed for all subobjects/properties (pointers/ints/strings/other objects) which reside in the object itself. On object creation, take up precalculated memory. Functions inside classes (methods) are no different than "normal" functions, it is just that compiler enforces them to be called on object or inside of fashion due to object-oriented programming philosophy.

When you try to get/set certain property of an objects, compiler actually translates it into memory offset from start of objects memory, so yes, you couldsay it acts like array with different data types in it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.