What Is OOP? 

For simplicity, object-oriented programming focuses on the data before anything else. How data is modeled and manipulated by the use of objects is fundamental to any object-oriented program.

What Are Objects?

If you look around the world, you will see objects everywhere. Maybe now you drink coffee. The cup of coffee is an object, the coffee in the cup is an object, even in the mountain that sits in a well. OOP realize that if you build an application is more likely that we will try to represent the real world. This can be done through the use of objects.

State of an Object

Each object has a state. That, at any time, which can be described from the material. Bob looked away again. Say we have designed our Person class to store the following information about a person: name, hair color, height, weight and address. 

When a new person object is created and stored data on Bob, these properties are associated with the state of Bob. For example today, Bob might have brown hair, 205 pounds, and live next door. Tomorrow, Bob might have brown hair, 200 pounds and moved to a new location across town. 

If we update the object data of the person of Bob to reflect your new weight and send change the object state. In Java, the state of an object is carried out in the fields. In the above example, we would have five fields of the kind of person; name, hair color, height, weight and address.



Behavior of an Object

Each object behaviors. In other words, an object has a certain set of actions that you can perform. Back to our first type of object - a book. Definitely a book does nothing? Let's say our tracking application is the book for a library. 

There is a book a lot of action, it can be controlled, recorded, upgraded, lost, and so on. In Java, an object behaviors are written in the methods. If a behavior of an object needs to be done, you call the corresponding method. 

Returning to the example again. Our reservation tracking application was adopted by the library and production have defined a method in our class book. We also added a field called borrower to keep track of who has the book. 

The method of producing record is written in the area of ​​the borrower with the name of the person the book is updated. Bob goes next to the library and check a book. The state of the object book is updated to reflect the fact that Bob now has the book.

Data Encapsulation

One of the fundamental concepts of object-oriented programming is that to change the state of an object, one of the behaviors of the object to be used. Or to put it another way, to change the data in one of the fields of the object, one of its methods to be called. This data is called encapsulation. 

Applying idea of ​​encapsulating data about objects we hide the details of how data is stored. We also objects are independent of each other as possible. 

An object contains data and the ability to manipulate in one place. This makes it easy for us to use that item, along with a Java application. There is no reason why we could not bring our class book and add it to another application that could also organize the data in the books.

Post a Comment

 
Top