Você está na página 1de 4

Keyplanns Java Tutorial

Chapter 1.

Keyplanns Java Lessons

1. Object-Oriented Programming concept


2. Class and Object

1.1 Object-Oriented Programming

hat is Object-Oriented Programming? It is a programming language model


that defines real world entities as objects. The implementation of this
programming model is based on the interactions among these objects. For
example, a customer (object) purchases textbooks (object) in a bookshop
management program (Object-Oriented Program).

Advantages of Object-Oriented Programming


Reusability: Existing codes can be easily re-used for another objects. This is
often called Inheritance in Object-Oriented Programming. To put it simply,
we can create new objects with small changes based on existing ones. For
example, when you create racing car objects, you can inherit such basic
properties from normal car object as wheels, handles, axels, and so on.
Technically speaking, inheritance happens at class level. It also reduce
redundancy and repetition of codes.
Maintainability: Object-Oriented Program separates the structure (class) of
an object and actual objects. It minimizes the effect of changes in the
structure on source programs. Therefore, it is easy to mend and maintain
programs.
Modularity: Since objects exist independently, it is easy to identify errors or
bugs by looking into each of them not the whole program. For example, when
you have some problem with graphic card in your computer, you dont need to
check CPU or LAM, but only the graphic card. To make it easier, you can think
each part of the computer as objects.

2.1 Class and Object

lass and Object are the most basic and important concepts to understand and
develop Object-Oriented Programs.

Class
Class is a template that defines the type of an object. It contains common
traits and behaviors for multiple objects. Lets say that you are developing

video store management program, then you will need to allow it to create new
customer which is an object at programming level. What are the common
traits and behaviors that the program should store for each customer in
relation to video shop? Traits would be name, phone number rental video and
address which are attributes and behaviors would be renting and returning
videos which are methods. In other words, those common traits and behaviors
are declared in a class through which multiple customers can be created with
different values for attributes and methods.

[ Picture 1 ] Class and Object

Object
As I have mentioned above, objects in Object-Oriented programming refer to real
world entity such as a book, person, a car and so on. These objects consist of two
factors which are state and operations. The state represents the actual values for
attributes.

[ Picture 2 ] Values for Attribute

Then the operations declare the actions that objects can do in a program. For
example, customer objects in the video management program can rent videos by
executing Rent method.

[ Picture 3 ] Method

These objects are also called Instance of a class, and creating objects through a
class is often called instantiate objects from a class.

Você também pode gostar