|
15 | 15 | "cell_type": "markdown",
|
16 | 16 | "metadata": {},
|
17 | 17 | "source": [
|
18 |
| - "In this lecture we will aim to cover:\n", |
| 18 | + "In this lecture we aim to cover:\n", |
19 | 19 | "- OOP\n",
|
20 | 20 | "- Decorators"
|
21 | 21 | ]
|
|
307 | 307 | "my_person = Person(\"donald knuth\", 84, \"computer scientist\")\n",
|
308 | 308 | "my_person.introduce()\n",
|
309 | 309 | "\n",
|
310 |
| - "\n", |
311 | 310 | "# DO NOT MODIFY\n",
|
312 | 311 | "assert my_person.eat(\"pasta\") == \"donald knuth is eating pasta\", \"Test failed: Something went wrong, expected 'donald knuth is eating pasta'\""
|
313 | 312 | ]
|
|
316 | 315 | "cell_type": "markdown",
|
317 | 316 | "metadata": {},
|
318 | 317 | "source": [
|
319 |
| - "We can now represent a person with attributes name, age, and profession. We can introduce a person, and a person can eat." |
| 318 | + "We can now represent a person with attributes name, age, and profession. We can introduce a person, and a person can eat.\n", |
| 319 | + "This brings us to one of the core principles associated with OOP, **encapsulation**: the object's methods and attributes\n", |
| 320 | + "are bundled as a single-unit. We also **abstract** away the implementation details of each method. As a programmer you can invoke `eat`\n", |
| 321 | + "or `introduce` without having to worry about what's going on in the background." |
320 | 322 | ]
|
321 | 323 | },
|
322 | 324 | {
|
|
465 | 467 | "cell_type": "markdown",
|
466 | 468 | "metadata": {},
|
467 | 469 | "source": [
|
468 |
| - "### Intermission: Decorators\n", |
469 |
| - "Before we continue exploring object-oriented programming, let's have a look at decorators.\n", |
| 470 | + "# Decorators\n", |
| 471 | + "Finally, let's have a look at decorators.\n", |
470 | 472 | "\n",
|
471 | 473 | "Congratulations, you've just been hired by the *National X-Soc Co-op Bank Ltd* to develop their ATM system!\n",
|
472 | 474 | "\n",
|
|
600 | 602 | "For now, you don't need to worry about the implementation details. The important part is understanding what decorators do: modify the behavior of an existing function."
|
601 | 603 | ]
|
602 | 604 | },
|
603 |
| - { |
604 |
| - "cell_type": "markdown", |
605 |
| - "metadata": {}, |
606 |
| - "source": [ |
607 |
| - "**[INSERT diagram for class vs object]**" |
608 |
| - ] |
609 |
| - }, |
610 |
| - { |
611 |
| - "cell_type": "markdown", |
612 |
| - "metadata": {}, |
613 |
| - "source": [ |
614 |
| - "TBD:\n", |
615 |
| - "- polymorphism/abstraction/encapsulation a little bit\n", |
616 |
| - "- then intermission on anotations\n", |
617 |
| - "- static and class methods" |
618 |
| - ] |
619 |
| - }, |
620 |
| - { |
621 |
| - "cell_type": "markdown", |
622 |
| - "metadata": {}, |
623 |
| - "source": [] |
624 |
| - }, |
625 | 605 | {
|
626 | 606 | "cell_type": "markdown",
|
627 | 607 | "metadata": {},
|
|
0 commit comments