Today, we start super important topic, many even of engineers couldn't apply in practice all aspects
of this knowledge because to understand this topic from all sides, you need to practice a lot as you
get more experience or information, which I'm going to share with you will start to make sense.
I spent a lot of time to select the right person to make complex things easier.
And today I will try to explain you object oriented programming.
So today, let's start from OPIS basics.
In this lesson we'll learn theory and I will explain in simple words what object oriented programming
is, where we are going to discuss what object oriented programming means.
And it is always better to understand first why we need or be and how it can help us in creating software.
We'll briefly discuss functional programming approach so you would be able to understand the difference
and better understand OPIS approach and take into account that this is a lesson about all basics.
We'll talk about key object oriented programming principles.
So let's start let's come up with a definition of OPIS first.
There are multiple definitions of what is or B, I'm going to share with you different ones.
And my own Wikipedia tells us that OPIS is programming paradigm based on the concept of object as a
definition of OPIS is the next one or is a computer programming model that organizes software design
around the objects rather than functions.
This definition clearly describes the difference between all AP and functional programming.
We'll talk about functional programming a little bit later.
My own definition sounds like this object oriented programming is a software design approach in which
concept of object occupies the first place.
In each definition we see that the concept of object is mentioned.
OK, then let's find the answer on the next question.
What is the object and object oriented programming?
Everything is an object.
Array is our object.
Connection to database is the object and expect the situation during the program.
Execution is the object, but this definition is very vast.
We need more specifics and let me simplify the definition of the object.
Imagine a car, a car, doors, headlights, body wheels, trunk engine and sided steering wheel color
and lots more.
What we have just described is called data structure.
We describe something abstract with key properties which allow us to distinguish car from plane.
Right now we have nothing more than a list of properties, which brings us to specific data organization
that enables efficient access and modification.
We can change wheels if we want, or we can change color of the car.
But this will be still a pure data structure in our program.
What does this car need to become an object?
This car needs to have behavior which will allow to manipulate with its own data the properties we have
listed.
We call this behavior methods.
Imagine that car has such behavior, astroland the headlight or start engine or turn right or turn left
and so on.
In case our car has such behavior, we can call it the object.
Now let me share with you my own definition of object.
Object, first of all, is a visual entity with a specific list of properties which can distinguish
it from other objects and behavior which allow to manipulate with these properties.
In other words, data plus behavior equals to object.
Does it make sense?
Object is always an instance of some specific class.
Things become more interesting.
Now we need to understand what acrostics.
I will try to explain what class is in a few words, because we are going to have separate lesson dedicated
to classes.
But I need to understand the concept of the class now to understand what object is.
Treat the class as the template for an object.
Imagine you a car manufacturer and you need to create millions of cars.
You know that each car will have color wheels, body, headlights, engine and lots more.
We also know that car should be able to drive, start and stop engine, accelerate, brake and so on.
We have just described the class for a car with properties and behavior, but each car might have different
color, different, but a petrol engine or diesel engine or electric one.
Besides that, each car can drive radically differently, I believe.
Now you understand that object.
Always an instance of some class.
If you understand this, we already probably are interested.
What are the approaches for software development exist?
One of the most popular programming paradigms is functional programming.
If an object oriented programming, our main concept is object in functional programming, our main
concept is function.
In other words, functional programming is not bothering about grouping data together with related behavior
and about describing of control flow.
We have specific task and we have specific functions that can deal with this task.
Functional programming expresses the logic of a computation which approach is better.
This is wrong question.
Because it is not complete enough.
The right question is which approach is better for some specific task because functional programming
approach works the best way.
You don't care about order of functions, execution for simple data manipulations, functional programming,
solution in some degrees, easier and faster to implement.
Sometimes it is even easier to support, but for complex enterprise solutions, functional programming
approach can turn your project maintenance in the nightmare.
Object oriented approach allows you to organize your code and programming execution in structured way.
During the course, we'll discuss with you different Glynco techniques, which relies on basic principles.
So now I believe you understand the difference between ALBE and functional programming.
Let's name exact reasons why and when we need to follow OPIS design.
Nowadays, you can't implement mobile application of web application if you don't understand or B approach
or in most cases the most natural and pragmatic approach.
I'm not trying to say is that OP is the one true way.
I just want to highlight the list of advantages which in most cases helps to solve even complex software
development tasks, modularity.
And in case something goes wrong in your program, you know where to look at their problems with calculation
of personal discount for user would need to take a look at user object.
If you would follow key or P principles, your code will be structured or allows you to have low coupling
in your code and high cohesion, which makes maintenance of your code much easier.
Scalability because of modularity.
And if you follow opis design principles, you can scale your software easily and in a predictable manner.
If you don't follow opihi approach, adding a new piece of functionality in your program may cause significant
changes in all existing code, which in turn increased risk of new defects associated with those changes.
Lower cost of development or BYDESIGN allows you to reuse code.
When you reuse code, you decrease the number of places where potential defects can appear.
Also, spend less time to reuse already existing method than to write new methods from scratch.
Security and reliability.
Basic principles allow you to hide details of implementation from user of your objects.
Or ByDesign allows you to build a robust design with independent modules that in turn makes the software
more secure and reliable.
Definitely, when you become senior developer, you would find disadvantages in orbit.
But when a candidate starts arguing with me during the interview and hating OPIS approach, usually
I ask him what is better for some imaginary business case?
And these people always lose this fight because they need to understand that programming is always just
a question of tradeoffs between maintainability, scalability, speed of development, good quality
and reliability.
And now when you understand on a high level what is object oriented programming and why we need to learn
it, let's review.
Basic core principles are inheritance, encapsulation, polymorphism, abstraction.
Let's go one by one inheritance to understand inheritance, let's consider the next example the remember
we discussed a class of the car in this lesson and now imagine that you need to create not Sadun but
sports car or family car was Xerces.
Would you describe class for sport car from scratch.
You don't need to do this because sports car also going to have four wheels, also going to have engine,
but something will be different.
Most likely you are going to have only two seats in the car and additional attributes of the sports
car like smaller probably clutch pedal for sport, manual transmission and something else.
I believe you got my point.
Inheritance allows you to create a new class based on another one.
New class can extend existing one and share properties and behavior.
New class is called child class and by the class is called parent class.
Inheritance allows you to reuse code and to create new classes without reinventing the wheel encapsulation.
The key principle tells us to keep data and code that can manipulate this data together.
It is also about keeping data and the code safe from external interference.
To understand it better, let me demonstrate encapsulation.
In real life, you have a car.
Car is a separate object and there is a gas pedal in it.
Gas pedal is external interface, which said the way how will interact with our car.
When we push down gas pedal, a lot of things happen.
The throttle is open to let some air in.
Meanwhile, food is fed to intake.
Manifold sensors regulate when throttle should be closed and so on and everything is done to accelerate
your car.
Do you see how many details are encapsulated from you inside the car?
But you don't care.
You don't want to control all these actions.
You just want to push gas pedal to accelerate your car and you don't have access.
Control how much food to feed in different cases, you'll get your car handle such kind of questions,
do you understand better now?
What is encapsulation in programming and modifiers exist to facilitate the encapsulation of components.
For example, in Java you have next access modifiers privat the strictest one.
You have access to fields and methods only within the specific class.
You can't access private elements outside of this class default access level.
Within the same package, elements with default access modifier can be accessed outside of the package
protected access level within the package and outside of the package.
In the channel classes access outside of the package and outside of a child class is not possible.
Public access level from everywhere.
You can access elements with public money, fire from within the class, outside of the class, within
the package and outside of the package to keep focus on the basic principles.
In this lesson, we'll discuss on the theory in the next.
Lessons will make a deep dive into practice part, including access modifiers.
I believe now it is clear what this encapsulation principle means.
The next principle is polymorphism.
Let me explain polymorphism in simple words and again of Óscar example.
Imagine you have two different cars.
One was electric engine, another was petrol engine.
Both are going to have Botten start engine.
In most cases, behaviour will be similar, engine will be started and you will be able to drive.
But the way how engine will be started is completely different.
In Kavis, petrol engine car system will feed fuel to the engine to start it in Kavis Electric Engine,
a huge blast of power will drive car like it's shown on the slide.
You have steering the wheel and each car has.
But the way how a steering system work is different in each car.
In this example you can have a single interface, but multiple implementations do feel what polymorphism
is all about.
The same word can mean different things in different contexts.
What we have just discussed called method overriding you your right behaviour in the separate lesson.
I am going to show you how polymorphism works in Java.
For now, I need you to understand the concept of OPIS and basic principles.
And the last but not least principle is abstraction and some literature.
This principle even not mentioned as a basic or principle, but I believe we can consider as this principle
as important as other ones we discussed.
Let me explain of what abstraction is.
If I would ask you, what is the difference between the car and the plane?
What will you say?
You would try to list some key features of a car and the plane.
You're trying to come up with abstraction, which should be enough to differentiate car and plane,
create abstraction, which works the best for your business needs.
It is not easiest thing to do, but if you create good abstraction for a specific case, it would allow
you to not duplicate code to support good scalability of your units and lots more.
This principle is a very important one and it requires time to use it in the right manner.
Let's take a look now.
What we have learned today, the we learned what is or be and what is the difference between object
oriented and functional programming.
We discuss advantages of OPIS and why we need to learn it.
And what is also very important.
We learned basic principles.
That's all what I wanted to share with you in this lesson.
This is our start of learning of object oriented programming.
I would be glad to recommend your literature to read as your homework, but I wouldn't recommend you
read anything.
So far my opinion, the topic of object oriented programming in majority books described chaotically
by saying this, I mean in books, a lot of terms, cost structures, new keywords, which we are going
to learn are mixed in the same chapters.
I spent a lot of time thinking on the structure of lessons and how to explain to my students and my
experience of teaching proofs that the sequence of lessons which I suggest brings a clear vision of
OPIS in the shortest possible time.
So now make sure you understand the content of this lesson before we move further.