0
Challenge · 77CS Fundamentals
Classes and objects
OOPused in ~100% of apps
Object-oriented programming comes up in every round at every company, and it is the half of the interview most people leave until the night before. The good news is that the questions are predictable and the answers are short, provided you can give a reason rather than a definition.
Core idea. A class is a description. An object is one thing built from that description, holding its own data and carrying the operations that are allowed on it. Keeping the data and the operations together is the point, because it means there is one place where the rules about that data live.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
tick the behaviours an item needs
with inheritance
class PlainItem
One class per combination. Three behaviours need 8 classes, and a fourth needs 16.
with composition
traits: []
One item, a list of behaviours. Three behaviours need 3 functions, and a fourth needs 4.
Inheritance grows as two to the number of behaviours. Composition grows as the number of behaviours.
↑ play a little first, then dig in