phone: 016-6933793
e-mail: darknessofsorrow@hotmail.com

Sunday 28 October 2012

Class and Object

 
   ~ Object - represents either objects in the real world like automobiles, houses, and employee records or abstractions like colors, shapes, and words.
   ~ Objects have state, behaviour and identity.
      State : The condition of an object at any moment, affecting how
                  it can behave
      Behaviour : Define by a set of methods, invoking a method on an
                  object means that asking the object to perform a task.

  Identity : Each object is unique.
~ Objects are categorized into classes.
~ Each individual object is an instance of a class.


~Class - the definition of a kind of object. It is like a plan or a blueprint for constructing specific objects.


A Class as a blueprint











 Objects that are instantiations of the class Automobile.


~ Class is a caterogy of objects that share the same :
  • Attribute
  •    + A named property of a class that describes a range of values
          that instances of the attribute might hold.
       + Attribute are the way classes encapsulate data.
       + Example :
              Class : Employee
              Attributes : employee_name, employee_id,
                                 position, department etc...
  • Operation
  •    + A behavior of an object
       + Implemented in classes are methods
       + Methods are the identified and invoked by their signature,
          including name, parameters, and return type
       + Example :
               Class : Employee
               Attributes : employee_name, employee_id,
                                  position, department, salary etc...
               Operations : setEmployeeDetails
                                   calculateSalary
                                   printEmployeeDetails




    ~ Programmers often use a simpler graphical notation to summarize some of the main properties of a class. This notation is called a UML class diagram or simply a class diagram.
    *UML - Universal Modeling Lamguage

    A Class Outline as a UML Class Diagram









    ~ Declaration of object & assigning of an object reference to the variable.
                ClassName objectRefVar = new ClassName ( ) ;   
             Example :   Vehicle car = new Vehicle ( ) ;  
    ~After an object is created, its data can be accessed and its methods invoked using the dot operator (.). 
      + objectRefVar . dataField - References a data field in the object
      + objectRefVar . method (arguments) - Invokes a method on the object
         Example : + Car . colour - References the colour in Vehicle
                            class
                         + Car . printColour ( ) ;
                         - Invokes the printColour() method on Car .
                             Methods are invoked as operations on objects.

    0 comments: