File size: 21,056 Bytes
f99add3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | 1
00:00:05,000 --> 00:00:11,000
Today, we start super important topic, many even of engineers couldn't apply in practice all aspects
2
00:00:11,000 --> 00:00:17,000
of this knowledge because to understand this topic from all sides, you need to practice a lot as you
3
00:00:17,000 --> 00:00:21,000
get more experience or information, which I'm going to share with you will start to make sense.
4
00:00:22,000 --> 00:00:26,000
I spent a lot of time to select the right person to make complex things easier.
5
00:00:26,000 --> 00:00:30,000
And today I will try to explain you object oriented programming.
6
00:00:30,000 --> 00:00:33,000
So today, let's start from OPIS basics.
7
00:00:33,000 --> 00:00:38,000
In this lesson we'll learn theory and I will explain in simple words what object oriented programming
8
00:00:38,000 --> 00:00:42,000
is, where we are going to discuss what object oriented programming means.
9
00:00:42,000 --> 00:00:48,000
And it is always better to understand first why we need or be and how it can help us in creating software.
10
00:00:49,000 --> 00:00:54,000
We'll briefly discuss functional programming approach so you would be able to understand the difference
11
00:00:54,000 --> 00:01:00,000
and better understand OPIS approach and take into account that this is a lesson about all basics.
12
00:01:00,000 --> 00:01:03,000
We'll talk about key object oriented programming principles.
13
00:01:03,000 --> 00:01:08,000
So let's start let's come up with a definition of OPIS first.
14
00:01:08,000 --> 00:01:13,000
There are multiple definitions of what is or B, I'm going to share with you different ones.
15
00:01:13,000 --> 00:01:20,000
And my own Wikipedia tells us that OPIS is programming paradigm based on the concept of object as a
16
00:01:20,000 --> 00:01:26,000
definition of OPIS is the next one or is a computer programming model that organizes software design
17
00:01:26,000 --> 00:01:29,000
around the objects rather than functions.
18
00:01:29,000 --> 00:01:33,000
This definition clearly describes the difference between all AP and functional programming.
19
00:01:33,000 --> 00:01:36,000
We'll talk about functional programming a little bit later.
20
00:01:36,000 --> 00:01:42,000
My own definition sounds like this object oriented programming is a software design approach in which
21
00:01:42,000 --> 00:01:44,000
concept of object occupies the first place.
22
00:01:45,000 --> 00:01:48,000
In each definition we see that the concept of object is mentioned.
23
00:01:49,000 --> 00:01:52,000
OK, then let's find the answer on the next question.
24
00:01:52,000 --> 00:01:55,000
What is the object and object oriented programming?
25
00:01:55,000 --> 00:01:56,000
Everything is an object.
26
00:01:57,000 --> 00:01:58,000
Array is our object.
27
00:01:58,000 --> 00:02:02,000
Connection to database is the object and expect the situation during the program.
28
00:02:02,000 --> 00:02:06,000
Execution is the object, but this definition is very vast.
29
00:02:07,000 --> 00:02:11,000
We need more specifics and let me simplify the definition of the object.
30
00:02:11,000 --> 00:02:19,000
Imagine a car, a car, doors, headlights, body wheels, trunk engine and sided steering wheel color
31
00:02:19,000 --> 00:02:20,000
and lots more.
32
00:02:20,000 --> 00:02:23,000
What we have just described is called data structure.
33
00:02:23,000 --> 00:02:28,000
We describe something abstract with key properties which allow us to distinguish car from plane.
34
00:02:28,000 --> 00:02:33,000
Right now we have nothing more than a list of properties, which brings us to specific data organization
35
00:02:33,000 --> 00:02:36,000
that enables efficient access and modification.
36
00:02:37,000 --> 00:02:41,000
We can change wheels if we want, or we can change color of the car.
37
00:02:41,000 --> 00:02:44,000
But this will be still a pure data structure in our program.
38
00:02:45,000 --> 00:02:47,000
What does this car need to become an object?
39
00:02:47,000 --> 00:02:53,000
This car needs to have behavior which will allow to manipulate with its own data the properties we have
40
00:02:53,000 --> 00:02:54,000
listed.
41
00:02:54,000 --> 00:02:56,000
We call this behavior methods.
42
00:02:57,000 --> 00:03:04,000
Imagine that car has such behavior, astroland the headlight or start engine or turn right or turn left
43
00:03:04,000 --> 00:03:04,000
and so on.
44
00:03:05,000 --> 00:03:08,000
In case our car has such behavior, we can call it the object.
45
00:03:09,000 --> 00:03:12,000
Now let me share with you my own definition of object.
46
00:03:12,000 --> 00:03:17,000
Object, first of all, is a visual entity with a specific list of properties which can distinguish
47
00:03:17,000 --> 00:03:22,000
it from other objects and behavior which allow to manipulate with these properties.
48
00:03:22,000 --> 00:03:26,000
In other words, data plus behavior equals to object.
49
00:03:26,000 --> 00:03:27,000
Does it make sense?
50
00:03:27,000 --> 00:03:30,000
Object is always an instance of some specific class.
51
00:03:31,000 --> 00:03:32,000
Things become more interesting.
52
00:03:33,000 --> 00:03:35,000
Now we need to understand what acrostics.
53
00:03:35,000 --> 00:03:40,000
I will try to explain what class is in a few words, because we are going to have separate lesson dedicated
54
00:03:40,000 --> 00:03:41,000
to classes.
55
00:03:42,000 --> 00:03:46,000
But I need to understand the concept of the class now to understand what object is.
56
00:03:46,000 --> 00:03:49,000
Treat the class as the template for an object.
57
00:03:49,000 --> 00:03:53,000
Imagine you a car manufacturer and you need to create millions of cars.
58
00:03:54,000 --> 00:04:00,000
You know that each car will have color wheels, body, headlights, engine and lots more.
59
00:04:00,000 --> 00:04:06,000
We also know that car should be able to drive, start and stop engine, accelerate, brake and so on.
60
00:04:07,000 --> 00:04:12,000
We have just described the class for a car with properties and behavior, but each car might have different
61
00:04:12,000 --> 00:04:17,000
color, different, but a petrol engine or diesel engine or electric one.
62
00:04:17,000 --> 00:04:21,000
Besides that, each car can drive radically differently, I believe.
63
00:04:21,000 --> 00:04:22,000
Now you understand that object.
64
00:04:22,000 --> 00:04:24,000
Always an instance of some class.
65
00:04:24,000 --> 00:04:28,000
If you understand this, we already probably are interested.
66
00:04:28,000 --> 00:04:31,000
What are the approaches for software development exist?
67
00:04:32,000 --> 00:04:35,000
One of the most popular programming paradigms is functional programming.
68
00:04:35,000 --> 00:04:41,000
If an object oriented programming, our main concept is object in functional programming, our main
69
00:04:41,000 --> 00:04:42,000
concept is function.
70
00:04:42,000 --> 00:04:48,000
In other words, functional programming is not bothering about grouping data together with related behavior
71
00:04:48,000 --> 00:04:50,000
and about describing of control flow.
72
00:04:51,000 --> 00:04:55,000
We have specific task and we have specific functions that can deal with this task.
73
00:04:55,000 --> 00:05:00,000
Functional programming expresses the logic of a computation which approach is better.
74
00:05:01,000 --> 00:05:02,000
This is wrong question.
75
00:05:03,000 --> 00:05:04,000
Because it is not complete enough.
76
00:05:05,000 --> 00:05:10,000
The right question is which approach is better for some specific task because functional programming
77
00:05:10,000 --> 00:05:12,000
approach works the best way.
78
00:05:12,000 --> 00:05:18,000
You don't care about order of functions, execution for simple data manipulations, functional programming,
79
00:05:18,000 --> 00:05:21,000
solution in some degrees, easier and faster to implement.
80
00:05:21,000 --> 00:05:27,000
Sometimes it is even easier to support, but for complex enterprise solutions, functional programming
81
00:05:27,000 --> 00:05:30,000
approach can turn your project maintenance in the nightmare.
82
00:05:31,000 --> 00:05:36,000
Object oriented approach allows you to organize your code and programming execution in structured way.
83
00:05:36,000 --> 00:05:42,000
During the course, we'll discuss with you different Glynco techniques, which relies on basic principles.
84
00:05:43,000 --> 00:05:47,000
So now I believe you understand the difference between ALBE and functional programming.
85
00:05:47,000 --> 00:05:51,000
Let's name exact reasons why and when we need to follow OPIS design.
86
00:05:51,000 --> 00:05:57,000
Nowadays, you can't implement mobile application of web application if you don't understand or B approach
87
00:05:58,000 --> 00:06:01,000
or in most cases the most natural and pragmatic approach.
88
00:06:02,000 --> 00:06:05,000
I'm not trying to say is that OP is the one true way.
89
00:06:05,000 --> 00:06:10,000
I just want to highlight the list of advantages which in most cases helps to solve even complex software
90
00:06:10,000 --> 00:06:13,000
development tasks, modularity.
91
00:06:13,000 --> 00:06:19,000
And in case something goes wrong in your program, you know where to look at their problems with calculation
92
00:06:19,000 --> 00:06:22,000
of personal discount for user would need to take a look at user object.
93
00:06:23,000 --> 00:06:29,000
If you would follow key or P principles, your code will be structured or allows you to have low coupling
94
00:06:29,000 --> 00:06:34,000
in your code and high cohesion, which makes maintenance of your code much easier.
95
00:06:34,000 --> 00:06:37,000
Scalability because of modularity.
96
00:06:37,000 --> 00:06:42,000
And if you follow opis design principles, you can scale your software easily and in a predictable manner.
97
00:06:43,000 --> 00:06:48,000
If you don't follow opihi approach, adding a new piece of functionality in your program may cause significant
98
00:06:48,000 --> 00:06:55,000
changes in all existing code, which in turn increased risk of new defects associated with those changes.
99
00:06:55,000 --> 00:07:00,000
Lower cost of development or BYDESIGN allows you to reuse code.
100
00:07:00,000 --> 00:07:05,000
When you reuse code, you decrease the number of places where potential defects can appear.
101
00:07:05,000 --> 00:07:10,000
Also, spend less time to reuse already existing method than to write new methods from scratch.
102
00:07:11,000 --> 00:07:13,000
Security and reliability.
103
00:07:13,000 --> 00:07:19,000
Basic principles allow you to hide details of implementation from user of your objects.
104
00:07:19,000 --> 00:07:26,000
Or ByDesign allows you to build a robust design with independent modules that in turn makes the software
105
00:07:26,000 --> 00:07:28,000
more secure and reliable.
106
00:07:28,000 --> 00:07:33,000
Definitely, when you become senior developer, you would find disadvantages in orbit.
107
00:07:33,000 --> 00:07:38,000
But when a candidate starts arguing with me during the interview and hating OPIS approach, usually
108
00:07:38,000 --> 00:07:42,000
I ask him what is better for some imaginary business case?
109
00:07:42,000 --> 00:07:48,000
And these people always lose this fight because they need to understand that programming is always just
110
00:07:48,000 --> 00:07:54,000
a question of tradeoffs between maintainability, scalability, speed of development, good quality
111
00:07:54,000 --> 00:07:55,000
and reliability.
112
00:07:55,000 --> 00:08:00,000
And now when you understand on a high level what is object oriented programming and why we need to learn
113
00:08:00,000 --> 00:08:01,000
it, let's review.
114
00:08:01,000 --> 00:08:09,000
Basic core principles are inheritance, encapsulation, polymorphism, abstraction.
115
00:08:09,000 --> 00:08:16,000
Let's go one by one inheritance to understand inheritance, let's consider the next example the remember
116
00:08:16,000 --> 00:08:22,000
we discussed a class of the car in this lesson and now imagine that you need to create not Sadun but
117
00:08:22,000 --> 00:08:25,000
sports car or family car was Xerces.
118
00:08:25,000 --> 00:08:28,000
Would you describe class for sport car from scratch.
119
00:08:28,000 --> 00:08:34,000
You don't need to do this because sports car also going to have four wheels, also going to have engine,
120
00:08:34,000 --> 00:08:36,000
but something will be different.
121
00:08:36,000 --> 00:08:41,000
Most likely you are going to have only two seats in the car and additional attributes of the sports
122
00:08:41,000 --> 00:08:46,000
car like smaller probably clutch pedal for sport, manual transmission and something else.
123
00:08:46,000 --> 00:08:48,000
I believe you got my point.
124
00:08:48,000 --> 00:08:52,000
Inheritance allows you to create a new class based on another one.
125
00:08:52,000 --> 00:08:56,000
New class can extend existing one and share properties and behavior.
126
00:08:56,000 --> 00:09:01,000
New class is called child class and by the class is called parent class.
127
00:09:01,000 --> 00:09:08,000
Inheritance allows you to reuse code and to create new classes without reinventing the wheel encapsulation.
128
00:09:08,000 --> 00:09:13,000
The key principle tells us to keep data and code that can manipulate this data together.
129
00:09:13,000 --> 00:09:17,000
It is also about keeping data and the code safe from external interference.
130
00:09:18,000 --> 00:09:20,000
To understand it better, let me demonstrate encapsulation.
131
00:09:20,000 --> 00:09:23,000
In real life, you have a car.
132
00:09:23,000 --> 00:09:26,000
Car is a separate object and there is a gas pedal in it.
133
00:09:26,000 --> 00:09:32,000
Gas pedal is external interface, which said the way how will interact with our car.
134
00:09:33,000 --> 00:09:36,000
When we push down gas pedal, a lot of things happen.
135
00:09:36,000 --> 00:09:39,000
The throttle is open to let some air in.
136
00:09:39,000 --> 00:09:42,000
Meanwhile, food is fed to intake.
137
00:09:42,000 --> 00:09:49,000
Manifold sensors regulate when throttle should be closed and so on and everything is done to accelerate
138
00:09:49,000 --> 00:09:50,000
your car.
139
00:09:50,000 --> 00:09:54,000
Do you see how many details are encapsulated from you inside the car?
140
00:09:54,000 --> 00:09:55,000
But you don't care.
141
00:09:56,000 --> 00:09:58,000
You don't want to control all these actions.
142
00:09:58,000 --> 00:10:02,000
You just want to push gas pedal to accelerate your car and you don't have access.
143
00:10:02,000 --> 00:10:08,000
Control how much food to feed in different cases, you'll get your car handle such kind of questions,
144
00:10:09,000 --> 00:10:10,000
do you understand better now?
145
00:10:10,000 --> 00:10:17,000
What is encapsulation in programming and modifiers exist to facilitate the encapsulation of components.
146
00:10:17,000 --> 00:10:22,000
For example, in Java you have next access modifiers privat the strictest one.
147
00:10:23,000 --> 00:10:27,000
You have access to fields and methods only within the specific class.
148
00:10:27,000 --> 00:10:33,000
You can't access private elements outside of this class default access level.
149
00:10:33,000 --> 00:10:39,000
Within the same package, elements with default access modifier can be accessed outside of the package
150
00:10:39,000 --> 00:10:43,000
protected access level within the package and outside of the package.
151
00:10:43,000 --> 00:10:50,000
In the channel classes access outside of the package and outside of a child class is not possible.
152
00:10:51,000 --> 00:10:53,000
Public access level from everywhere.
153
00:10:54,000 --> 00:10:59,000
You can access elements with public money, fire from within the class, outside of the class, within
154
00:10:59,000 --> 00:11:04,000
the package and outside of the package to keep focus on the basic principles.
155
00:11:04,000 --> 00:11:07,000
In this lesson, we'll discuss on the theory in the next.
156
00:11:07,000 --> 00:11:11,000
Lessons will make a deep dive into practice part, including access modifiers.
157
00:11:12,000 --> 00:11:15,000
I believe now it is clear what this encapsulation principle means.
158
00:11:16,000 --> 00:11:18,000
The next principle is polymorphism.
159
00:11:18,000 --> 00:11:22,000
Let me explain polymorphism in simple words and again of Óscar example.
160
00:11:23,000 --> 00:11:24,000
Imagine you have two different cars.
161
00:11:25,000 --> 00:11:28,000
One was electric engine, another was petrol engine.
162
00:11:28,000 --> 00:11:31,000
Both are going to have Botten start engine.
163
00:11:31,000 --> 00:11:36,000
In most cases, behaviour will be similar, engine will be started and you will be able to drive.
164
00:11:36,000 --> 00:11:40,000
But the way how engine will be started is completely different.
165
00:11:40,000 --> 00:11:47,000
In Kavis, petrol engine car system will feed fuel to the engine to start it in Kavis Electric Engine,
166
00:11:47,000 --> 00:11:52,000
a huge blast of power will drive car like it's shown on the slide.
167
00:11:52,000 --> 00:11:55,000
You have steering the wheel and each car has.
168
00:11:55,000 --> 00:11:58,000
But the way how a steering system work is different in each car.
169
00:11:58,000 --> 00:12:05,000
In this example you can have a single interface, but multiple implementations do feel what polymorphism
170
00:12:05,000 --> 00:12:06,000
is all about.
171
00:12:07,000 --> 00:12:10,000
The same word can mean different things in different contexts.
172
00:12:10,000 --> 00:12:16,000
What we have just discussed called method overriding you your right behaviour in the separate lesson.
173
00:12:16,000 --> 00:12:19,000
I am going to show you how polymorphism works in Java.
174
00:12:19,000 --> 00:12:24,000
For now, I need you to understand the concept of OPIS and basic principles.
175
00:12:24,000 --> 00:12:28,000
And the last but not least principle is abstraction and some literature.
176
00:12:28,000 --> 00:12:34,000
This principle even not mentioned as a basic or principle, but I believe we can consider as this principle
177
00:12:34,000 --> 00:12:37,000
as important as other ones we discussed.
178
00:12:37,000 --> 00:12:39,000
Let me explain of what abstraction is.
179
00:12:40,000 --> 00:12:43,000
If I would ask you, what is the difference between the car and the plane?
180
00:12:43,000 --> 00:12:44,000
What will you say?
181
00:12:45,000 --> 00:12:48,000
You would try to list some key features of a car and the plane.
182
00:12:48,000 --> 00:12:53,000
You're trying to come up with abstraction, which should be enough to differentiate car and plane,
183
00:12:53,000 --> 00:12:57,000
create abstraction, which works the best for your business needs.
184
00:12:57,000 --> 00:13:02,000
It is not easiest thing to do, but if you create good abstraction for a specific case, it would allow
185
00:13:02,000 --> 00:13:07,000
you to not duplicate code to support good scalability of your units and lots more.
186
00:13:07,000 --> 00:13:12,000
This principle is a very important one and it requires time to use it in the right manner.
187
00:13:13,000 --> 00:13:14,000
Let's take a look now.
188
00:13:14,000 --> 00:13:19,000
What we have learned today, the we learned what is or be and what is the difference between object
189
00:13:19,000 --> 00:13:20,000
oriented and functional programming.
190
00:13:21,000 --> 00:13:24,000
We discuss advantages of OPIS and why we need to learn it.
191
00:13:25,000 --> 00:13:26,000
And what is also very important.
192
00:13:26,000 --> 00:13:28,000
We learned basic principles.
193
00:13:29,000 --> 00:13:32,000
That's all what I wanted to share with you in this lesson.
194
00:13:32,000 --> 00:13:35,000
This is our start of learning of object oriented programming.
195
00:13:36,000 --> 00:13:40,000
I would be glad to recommend your literature to read as your homework, but I wouldn't recommend you
196
00:13:40,000 --> 00:13:41,000
read anything.
197
00:13:41,000 --> 00:13:47,000
So far my opinion, the topic of object oriented programming in majority books described chaotically
198
00:13:47,000 --> 00:13:53,000
by saying this, I mean in books, a lot of terms, cost structures, new keywords, which we are going
199
00:13:53,000 --> 00:13:56,000
to learn are mixed in the same chapters.
200
00:13:56,000 --> 00:14:02,000
I spent a lot of time thinking on the structure of lessons and how to explain to my students and my
201
00:14:02,000 --> 00:14:08,000
experience of teaching proofs that the sequence of lessons which I suggest brings a clear vision of
202
00:14:08,000 --> 00:14:10,000
OPIS in the shortest possible time.
203
00:14:10,000 --> 00:14:15,000
So now make sure you understand the content of this lesson before we move further.
|