Many name tags in one box: objects
Key and value were one tag, one value (lesson 11). But 'one person' can't be captured by a single fact. They have a name, an age, a hometown. Bundling these many tags into one box is an object.
Many tags in one box
Key and value in lesson 11
was a single pair like 'apple -> fruit'.
But to describe one person,
a single fact isn't enough.
Name, age, city... you need several pairs.
Gathering them into one box is an object.
Add the tags one by one. The pairs gather into one 'person' box.
Each tag is still just a key and a value.
What changed is that the scattered pairs
are now bundled into one box called 'person'.
So what does the whole box become?
The box is one 'thing'
Carrying name, age, and city separately
gets confusing fast.
But once bundled in a box,
the box itself becomes one person, 'Minsu'.
You can hand the whole person around at once.
Compare scattered pairs with a bundled 'person'. Bundled, it's handled as one.
Now 'Minsu' isn't a pile of tags
but one thing with properties.
So, from inside this box,
how do you pull out just the 'age'?
Peek inside with a dot
To pull a value from inside the box,
you name the box and the tag together.
Like 'Minsu's age', 'Minsu's city'.
Often written with a dot: minsu.age -> 12.
Point at the box, add a dot, then the tag you want.
Tap a tag. 'box.tag' picks out exactly that value.
You can now handle the whole box,
or any one value inside, freely.
But there isn't just one person, Minsu.
How do you make many people of the same shape?
Same shape, different contents
Once you decide which tags a 'person' has
(name, age, city),
you can stamp out many people from that shape.
Minsu, Sora, Tom all have the same fields,
but the values inside differ.
Stamp several people from the shape. Same fields, different values.
Making the same shape over and over from one mold
is convenient and means fewer mistakes,
because the tag names stay consistent.
This simple bundle is, in fact, almost all of a program.
A container for the real world, and beyond
A game character (name, hp, level),
a product (title, price, stock), a user (id, email).
Most of what a program handles is objects like these.
It puts the 'things' of the world into boxes and works with them.
Next, we'll see how similar objects inherit what they share.
Character, product, user. Tap through them. All the same 'things in a box'.
With key and value (lesson 11) you learned pairs,
and now you've bundled those pairs into 'one thing'.
Scattered information became a meaningful object.
Next, we'll see how similar things pass down
the parts they share: inheritance.