PF 101 · Object-Oriented Programming · Pre-final
Discussion
01 / 11
for-you.js
For You
Pre-final · Module 04 — why this post, not that one
PF 101 · New project Campus Feed Not Fighter Arena
New world
The arena is done. Put it away.
Midterm
You extended a starter. Warrior. Witch. attack(). Someone else wrote Game.
Pre-final
Blank js/. You type every class. The object is a post, not a fighter.
The hook
Your phone is not random
Something decided this video is worth more than your cousin’s photo. That something is a function with a name.
  • Stories scream, then vanish
  • Reels get paid for watch time
  • A photo with two likes can still lose to a dunk clip
The name
The function is called score()
Photo.score() → likes Story.score() → likes × 3 (or 0 if 24h old) Reel.score() → likes × 2 + seconds watched feed.forYou() → sort by score() → never asks the type
If Feed writes if (post is Reel), the magic is dead.
Map
Same pillars. New objects.
Content ├── Photo ├── Story expires └── Reel watch time Creator a name Feed HAS posts — composition, not extends
Four pillars
Where they hide in the feed
INHERIT
extends Content
Photo, Story, Reel reuse like() and caption.
POLY
score()
Same name. Three formulas. Feed calls one word.
ENCAP
#likes
You cannot cheat 999 likes. You call like().
Feel it
Canteen vs dunk vs expired crush
PostMathScore
Photo · 2 likes22
Story · 3 likes · 30 hours oldexpired0
Story · 2 likes · 2 hours old2 × 36
Reel · 1 like · 40s watched2 + 4042
The dunk wins. The crush story had more likes — and still lost. That is the algorithm.
Your island
Post what you actually scroll
  • Ferry cancelled — sleep in
  • Canteen sold out of siomai
  • Intramurals dunk from half court
  • Prof cancelled — story that dies tonight
Folder
The phone is empty until you type
campus-feed/
index.html phone frame only
css/feed.css
js/ you create every file
content.js
photo.js story.js reel.js
creator.js feed.js main.js
Not today
Leave these in midterm
  • ✕Fighter, Game, attack(), health bars
  • ✕Copy-paste from the starter
  • ✕if (post instanceof Reel) inside Feed
  • ✓Type every line. Know every line.
Next
Module 05 — you write the algorithm
Close Fighter Arena. Open campus-feed. The For You page is yours.
note //