@@ -53,11 +53,48 @@ const newCar = new Car('Toyota', 'Camry') // year defaults to 2024
5353const oldCar = new Car (' Ford' , ' Mustang' , 1965 ) // year explicitly set
5454```
5555
56- 🐨 Open <InlineFile file = " index.ts" /> and:
56+ 🐨 Open <InlineFile file = " index.ts" /> and create/export three classes :
5757
58- 1 . Use ` # ` prefix to create private fields
59- 2 . Use default parameter values in constructors
60- 3 . Create classes that encapsulate their internal state
58+ ### ` User `
59+
60+ - Public fields: ` name ` , ` email ` , ` role ` (all ` string ` )
61+ - Constructor ` (name, email, role = 'user') `
62+ - Omitting ` role ` must leave it as ` 'user' `
63+
64+ ### ` BankAccount `
65+
66+ - Public field: ` accountNumber ` (` string ` )
67+ - A private balance field (use ` # ` so it is inaccessible outside the class)
68+ - New accounts start with balance ` 0 `
69+ - ` deposit(amount: number) ` increases the balance by ` amount ` (it accumulates)
70+ - ` getBalance() ` returns the current balance
71+
72+ ### ` Config `
73+
74+ - Public fields: ` host ` (` string ` ), ` port ` (` number ` ), ` debug ` (` boolean ` )
75+ - Constructor defaults: ` host = 'localhost' ` , ` port = 3000 ` , ` debug = false `
76+ - ` new Config() ` must use all three defaults; custom args override them
77+
78+ Export all three : ` export { User, BankAccount, Config } `
79+
80+ ## Fixtures and success criteria
81+
82+ ``` ts
83+ const user = new User (' Alice' , ' alice@example.com' )
84+ const admin = new User (' Bob' , ' bob@example.com' , ' admin' )
85+ const account = new BankAccount (' 12345' )
86+ account .deposit (100 )
87+ account .deposit (50 )
88+ const config = new Config ()
89+ const customConfig = new Config (' example.com' , 8080 , true )
90+ ```
91+
92+ - ` user.role === 'user' ` and ` admin.role === 'admin' `
93+ - ` account.accountNumber === '12345' `
94+ - A fresh account has ` getBalance() === 0 `
95+ - After the deposits above, ` getBalance() === 150 `
96+ - Default config: ` host === 'localhost' ` , ` port === 3000 ` , ` debug === false `
97+ - Custom config: ` 'example.com' ` , ` 8080 ` , ` true `
6198
6299💰 Use ` # ` to declare a private field—it's truly private, not just a convention.
63100
0 commit comments