Introduction to OOP

15 minutes
Share the link to this page
Copied
  Completed

Transcript

Hi there, welcome back friends. In the comic series of lectures, we are going to learn about object oriented programming in Java. And here in this lecture, we're going to learn basic concepts and what is object oriented programming approach. So let's start. Basic object oriented concepts include a wide range of tools, we have class object polymorphism, encapsulation, inheritance, affection, modulation and more. We have overloading and such concept, we are going to learn about these things and try to implement these thing like writing a quote.

So let's start. In the programming languages, before the emergence of object oriented, we have the procedural approach, a procedural programming approach or procedure oriented programming, where we have global data, local data, to inform our study which are others We have different methods or functions and they interact with each other in that way, there is less code reusability the codes are generally very complex and it is hard to realize and implement with object oriented programming, we have certain things in mind. First of all we get a code reusability such that the data and functions or methods get used and reuse again and again in different format. We have different layers of visibility mode of production for data, we have the public private and protected mode which was missing in the earlier example, all variables will be either public or open or hidden completely but here we follow higher.

There we have a hierarchy of trades that are being implemented from different approach languages like C is completely procedural or language. Language like c++ is partially procedural and partially object oriented. Java is completely object oriented. I'm all things, there are different languages procedural programming languages out there, that you can classify in two categories. Object Oriented or hitting highlighted these days. And a typical example of procedural and object oriented apart from the programming while we can get if you say, you would need a funny chat table in your four year old.

In the procedural approach, you would first of all, sow the seed on the ground. Wait for the plant to grow, become a tree. Then we will cut down the tree a dragger timber or wood into planks, you would create the nails and hammer the nails together to form the table. That's why you have to work from stage one to stage again. And you have to wait a lot of time you have to do a lot of work on your own. So, when we have to create a new program, we cannot use the various functionalities of existing programs, we have to write it again and again.

But with object oriented approach, we have to simply go to the market, ask a blank, ask the hammer, and just get it done very easily. So, the task is being divided into different persons or different developers. And different developers working on the same project may divide different components of the software into different categories. One person will design UI one will design the back end logic one will design the Security modules and selection and you can use the traits that are being developed the format's of the security implementation in form of components that will be used again and again in the coming ways it will proceed production model and will be implemented in the industrial scale. So, object oriented could be also said as an industrial revolution, the procedural mechanism. So, let us understand what is a class and how classes are being implemented.

From the day one when you learned about Java programming and seeing the first Java code, you have seen the class variable, you have the syntax called class and you have been introduced to class that everything in Java is a part of a class. Every method or thing you write in a form of class. They are classes and you compile those classes. Render output. So, what is the class class is a category simply categorization of components and we want to divide those things. So, just imagine we have a jungle and in our jungle there are a huge range of animals.

So, we can have two different classes plants and animals. A plant class will consist of different categories of clients, which will be divided further into different classes or even objects. Similarly, we have animal class, and they will class we have different objects. a giraffe may be an object of animal class, a dog may be an object of animal class and elephant may be object of annual pass. A lamb may be any object of animal class. So, an object is a component or an instance of an object, in other words is also called as an instance of the class.

So in a sense, is a particular entity, which is a part of a class So, keep this thing in mind. Then we have nesting of classes you have seen nesting of effects nesting of for loops. Similarly we have nesting of classes and nesting is different here we have particular trees or the specialization to be called less nasty generalization is class if we want to generalize things, that there are we know at the top level and if we want to specialize things we move downwards. vehicle is a generalized form of all kinds of transportations available there. Then we make categorize it to the real or unreal rakers, then we can classify it to four wheelers or two wheelers. Then four wheelers could be classified as further as cars, trucks, and wall tanks as specific models are specific companies and a specific person's car specific unit these all are classes or components or you could divide these things.

When you are a car driver, you are interested only to know the mechanic. The tools that you can incorporate, you would be interested in understanding the concept of gears, how you can use the gear award a screen will be provided acceleration you could perform on different number of years, you will learn about air brakes, handbrake, emergency brakes, the steering wheel and such things you are not interested whether the car has two stroke engine, a four stroke engine, orange electric way you would not be interested in learning the final details of the internal combustion engine. So this is abstraction. You only know what you need, you don't need. You don't need to learn everything. So this is a modulation abstraction that is a feature of object oriented approach.

So there's a few differences or differences between procedural approach and object oriented approach. The procedural approach is a top down design. And the object oriented approach is focused on objects rather than design. We can move up or down anytime we want. The procedural approach has a limited code we use there, it could really use but with very limited conditions. With object oriented program, you can use the complete program a complete method, a complete set of variables completely structure.

Complete class are different things. You could use things more and more over and over again, in the form of overloading and different things. With procedural approach, the code gets complex when you try to build a huge solution. But without data oriented, the solution would not be having a complex or a complex design or implementation, you need to understand how things are being integrated, you have to build the small things and integrated Yeah, in a very patient manner. With the procedure approach, the focus is on global data and with object oriented, we have focused on protected and public private data. The public private and protected data concept is similar.

I will tell him inheritance. There's classes and instances we know a classical be classified as a generalized entity having the same behavior of different instances. So there will be 10 top top 10 buildings called skyscrapers and the building would be honest In class, there will be different instances say bush Khalifa or Taipei when a one tower Empire State Building such a new instance of ruling class similarly, we have more classes or more buildings. Then we have encapsulation as a very, very important category of we have learned about the car, our car driver does not know how the car is being implemented. Actually, we just he knew how to drive the car, how to fix errors. So, encapsulation is keeping different matters objects and variables that are not required to be learned by outsider, it will be encapsulated or hidden inside the capsule, you could see all the the outer covering, you cannot see the finer details.

So, such data which falls under the category of hidden to recall as private and protected data are those who are between private and public public data are available to everyone they can access or use that tanks visible it is visible to everyone, you have to explicitly tell those things to protect data is only visible to the same class, the variable the holder of variable class and the directly child direct child of that class. Anyone who's in editing So, what is a child class here? We have the concept of inheritance. Suppose you your grandfather has certain crease around in your home. He used to hide certain trees and he has a key for that critter. He does not want anyone outside his home other than his son, daughters and granddaughters grandsons, I do not want it to be known to anyone else.

So, he will provide the key to your father and you over and over time. So, this will be protected kind of data, but anything that is personal, do you fit in for his own privacy, such thing is not available to you or either your father, I will will only do him and things that are in the public domain like is a speech or books that can be written by him is available in the public domain that is called public. Similarly, we have more things here, there is a difference between procedural and object oriented in the manner that we implement things. Suppose we have a generalized function, four different shapes in the procedural approach, we have to define Each components in a single function, but object oriented, we can design a function once and modify its behavior. In different classes, we have defined a rotate and play some say functions once and we have changed the property over and over again for different kinds of shapes like Triangle Circle, and square.

Similarly, we can directly call or access and different functionalities of different classes. Here we have two classes a stack and queue. having different implementations of data structure Are we going to learn data. The main function we can call the objects of such classes, and access different things and perform various functions. Here we have created object as the name of the class our stack and queue. Remember this thing in the middle method, the talk method, we have created an object called capital cube for the class cube, and the object for the stack as capital S. That you can see here is a format of declaring it objects of a class.

Then we can access the methods and objects or variables directly on there those classes using the objects of the same class. By reading this Command F dot add, we can add, we can call the Add method of this tech class. In object oriented programming, we have different classes and different variables. They consist of many well encapsulated objects and interact with each other by sending different set of messages. That when we either tokens or differentiate of things, we can Perform a wide range of operations with object oriented programming. We're going to learn more in the coming lectures.

Till then keep learning and keep moving ahead

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.