Skip to content
Ameen Abozaid
BEG-019

OOP introduction

  • 5 Lessons
  • 58 min of reading
  • 1.5 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Procedural vs object-oriented programming
  • objects
  • classes
  • state
  • behavior

Learn first

58 min of reading · 1.5 h of practice (estimate)

Learning outcomes

  1. Contrast a procedural solution with an object-oriented one for the same problem.
  2. Identify objects, their state, and their behavior in a plain-language description.
  3. Explain the difference between a class and an object.

Lessons

  1. 01When procedural code stops scaling12 min read
  2. 02Objects: state + behavior11 min read
  3. 03Classes as blueprints11 min read
  4. 04Finding objects in a problem description12 min read
  5. 05Demo: rewriting a procedural bank as objects12 min read

Lab and exercises

Lab

BEG-019-LAB1 · Noun and verb hunt

Outcomes: 1, 2, 3 · Time: ~1 h From a one-page description of a bank (provided by the instructor), list candidate classes (nouns), their state, and their behaviors (verbs). Justify each choice and say which nouns you rejected and why. Acceptance: reasonable candidates with justification.

Exercises (assessment: quiz plus the noun/verb analysis)

IDOutcomeTask
BEG-019-EX011Write two or three sentences on what goes wrong when you store 500 accounts in parallel arrays.
BEG-019-EX021Sketch (in words) how the same deposit looks procedurally and object-oriented.
BEG-019-EX032For a library book, list three pieces of state and three behaviors.
BEG-019-EX042Underline nouns and verbs: "A student enrolls in a course. The teacher grades the exam."
BEG-019-EX053Explain class vs object using a cookie cutter and cookies (or your own analogy).
BEG-019-EX063Say whether each is a class or an object: Account, Ana's account, Customer, the customer named Omar.
Show solutions
  • EX01 Related values are split across arrays, easy to get out of sync, and any code can change any value with no protection; adding a field means editing everything.
  • EX02 Procedural: deposit(balances, 3, 50). OO: account.deposit(50); the account owns its balance.
  • EX03 For example state: title, author, isBorrowed. Behavior: borrow, return, describe.
  • EX04 Nouns: student, course, teacher, exam. Verbs: enrolls, grades.
  • EX05 The cutter is the class (shape defined once); each cookie is an object with its own state (e.g., icing).
  • EX06 Class, object, class, object.
  • Outcome 2 is also covered by the lab; all outcomes also appear in the quiz.

Quiz

Outcomes: O1 procedural vs OO · O2 state and behavior · O3 class vs object.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1A main problem of parallel arrays for accounts is:O1
  2. 2OOP groups together:O1
  3. 3Adding a currency field in the array version most likely requires:O1
  4. 4The balance of an account is:O2
  5. 5"Deposit" is:O2
  6. 6Two accounts built from the same class:O2
  7. 7A class is best described as:O3
  8. 8An object is also called a(n):O3
  9. 9How many objects can one class create?O3
  10. 10When hunting nouns in a description, you should:O2

Practical part

Complete the noun/verb analysis (BEG-019-LAB1) and the six exercises. Pass: quiz 7/10 and an analysis with justified candidates, rejecting at least one noun.

Common mistakes

A class per noun, including irrelevant ones; behavior separated from the data it acts on.

Assessment

Quiz plus the noun/verb analysis.

Career relevance

The start of domain modeling (MID-060, SRA-003).

Type to search levels, phases, modules and lessons.