If you've never used an object-oriented programming language before, you'll need to learn a few basic concepts before you can begin writing any code. This lesson will introduce you to objects, classes, inheritance, interfaces, and packages. Each discussion focuses on how these concepts relate to the real world, while simultaneously providing an introduction to the syntax of the Java programming language.
Modern OO languages provide the programmer with three capabilities that improve and simplify
the design of such programs: encapsulation, inheritance, and polymorphism (or generic functionality). Related topics involve objects, classes, and data hiding.Anobject combines various classical data types into a set that defines a new variable type, or structure. A class unifies the new entity types and supporting data that represents its state with routines (functions and subroutines) that access and/or modify those data. Every object created from a class, by providing the necessary data, is called an instance of the class. In older languages like C and F77, the data and functions are separate entities.
An OO language provides a way to couple or encapsulate the data and its functions into a unified entity. This is a more natural way to model real-world entities which have both data and functionality. The encapsulation is done with a “module” block in F90, and with a “class” block in C++. This encapsulation also includes a mechanism whereby some or all of the data and supporting routines can be hidden from the user. The accessibility of the specifications and routines of a class is usually controlled by optional “public” and “private” qualifiers. Data hiding allows one the means to protect information in one part of a program from access, and especially from being changed in other parts of the program. In C++ the default is that data and functions are “private” unless declared “public,” while F90 makes the opposite choice for its default protection mode. In a F90 “module” it is the “contains” statement that, among other things, couples the data, specifications, and operators before it to the functions and subroutines that follow it.
Objects
In programming terms, an object is a self-contained component
that contains properties and methods needed to make a certain type of
data useful. An object’s properties are what it knows and its methods
are what it can do. The project management application mentioned above
had a status object, a cost object, and a client object, among others.
One property of the status object would be the current status of the
project. The status object would have a method that could update that
status. The client object’s properties would include all of the
important details about the client and its methods would be able to
change them. The cost object would have methods necessary to calculate
the project’s cost based on hours worked, hourly rate, materials cost,
and fees.
Classes, instances, and instantiation
A class is a blueprint or template or set of instructions to build a specific type of object. Every object is built from a class. Each class should be designed and programmed to accomplish one, and only one, thing. Because each class is designed to have only a single responsibility, many classes are used to build an entire application.An instance is a specific object built from a specific class. It is assigned to a reference variable that is used to access all of the instance's properties and methods. When you make a new instance the process is called instantiation and is typically done using the
new
keyword.example :
public var myFirstObject:Sprite;
Then you create the new object—using the keyword
new
—and assign it to the reference variable.nameClass thisIsObject = new nameClass();
source :
http://www.adobe.com/devnet/actionscript/learning/oop-concepts/
http://www.oracle.com/
0 comments
Post a Comment