Java Object
Java Object
- Objects are keys to understanding object-oriented technology.
- They all have a state and a behavior or action based on one or more states.
- Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail).
- Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
-
For each object that you see, ask yourself two questions:
- What possible states can this object be in?
- What possible behavior or action can this object perform?
- Continue to determine which of these properties and/or actions that are of interest to use in your java-application.
- You may also notice that some objects, in turn, will also contain other objects.
- An object stores its states in member variables (fields).
- An object exposes its behavior or action through methods.
Object benefits.
-
Bundling code into individual software objects
provides a number of benefits, including:
-
Modularity:
The source code for an object can be written and maintained regardless of the source code for other objects. When objects are created, they can easily be passed around in the system.. -
Information-hiding:
By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world. -
Code re-use:
If an object already exists you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code. -
Plug ability and debugging ease:
If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement.
-
Modularity:
The main 3 Object Oriented Programming (OOP) Concepts.
-
Encapsulation:
-
Object legislates how its data may be accessed:
- Some data may be accessible to others, some not.
- Data can only be modified in specified ways - easier to ensure correctness.
-
Object legislates how its data may be accessed:
-
Inheritance:
-
One class may be a special case of another:
- Rectangle is like a square, plus a second (possibly) distinct value.
- Colored-Rectangle is like a rectangle, plus the concept of color.
-
One class may be a special case of another:
-
Polymorphism:
-
Different objects in a hierarchy behave correctly whatever
reference type to the object:
- shape.getArea() len*wid, if shape is a rectangle
- shape.getArea() PI*r2, if shape is a circle
- Don't worry - I will explain this in more detail later.
-
Different objects in a hierarchy behave correctly whatever
reference type to the object:
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.