24 Des 2011

Object, it's all about the concept of programing with an object

What Exactly Is a Class?
In short, a class is a blueprint for an object.When you instantiate an object, you use a class as the basis for how the object is built. Class is decipherable as group of objects that have atributes, operation, and relation.
Remember that each object has its own attributes (analogous to fields) and behaviors (analogous to functions). A class defines the attributes and behaviors that all objects created with this class will possess. Because objects are created from classes, it follows that classes must define the basic building blocks of objects (attributes, behavior, and messages). In short, you must design a class before you can create an object.

Attributes
Each class must define the attributes that will store the state of each object instantiated from that class.

Methods
Methods implement the required behavior of a class. Every object instantiated from this class has the methods as defined by the class. Methods may implement behaviors that are called from other objects (messages) or provide the fundamental, internal behavior of the class. Internal behaviors are private methods that are not accessible by other objects.

Messages
Messages are the communication mechanism between objects.


Using UML to Model a Class
Unified Modeling Language is a standardized modeling language that used to help system and software developers accomplish them tasks. one of the type of UML is UML Class Diagram.
Class Diagram is very useful. We can use it to illustrate the classes that we build, express the static structure of the objects and classes we want to model and the static blueprint of the program we want to build and it can help us to explain how the different classes interact with each other.

Encapsulation and Data Hiding
Encapsulation is a process to hiding data with their methods. Encapsulation principal function in order that user of the class does not need to know how the class is implemented.
For example, we can create a class that named is Circle. And the other class that named is Cone. Cone class wants to use one of method from the Circle class. such as method to find area of circle. And object of cone class can find the area of the circle without knowing how the area is computed. s
Data hiding is a major part of encapsulation. For data hiding to work, all attributes should be declared as “private” and the attribute isn’t part of Interface. That have purpose to keep the internal class from external access. Only the public methods are part of the class interface. Declaring an attribute as public breaks the concept of data hiding. Robust classes are designed with encapsulation in mind. Encapsulation and data hiding has two bases, Interface and implements.

Interface
Class interface contain methods, but without implementation. Interface defined as basic communication for two objects at different class. Object connected each other through interface. Any behavior that the object provides must be invoked by a message sent using one of the provided interfaces.

Interface should be able to explain to user about how they can interact with the class. In most OO languages, the methods that are part of the interface are designated as public. It’s because interface will be access by many class. After class accessing interface, the behavior will be implement on its self.

 For example, interface of the class named “Electronic”. Their object like AC, TV, Radio, etc. each object has a volume control. So, at interface class must have a same method to operate it, such as “Volume”. But without implementation, just have method and parameter. To control volume, each object can access method “Volume” from “Electronic” interface and they can implements on its self with they own way.

It is important to note that there are interfaces to the classes as well as the methods—don’t confuse the two. The interfaces to the classes are the public methods while the interfaces to the methods relate to how you call (invoke) them. This will be covered in more detail later

Implementations
Only the public attributes and methods are considered the interface. The user should not see any part of the implementation—interacting with an object solely through class interfaces.

The implementation can change, and it will not affect the user’s code. For example, the company that produces the calculator can change the algorithm (perhaps because it is more efficient) without affecting the result.

Tidak ada komentar:

Posting Komentar