Object-Oriented

Object-Oriented concept

:28/10/2008 by Poramaporn Ruamjinda

You should to known about :following

  • Classand Object
    • Class is abstraction of object,a template from which objects are created.
    • Class includes data(its attributes, fields or properties)and functionality(the things it can do, or methods, operations or features)
    • Class is at design time but Object is at run-time
    • Used Class for create an object,then use object for working
    • Object is a variable that type is a class
    • The object variable must be created(New) before using it

     Dim A,B as Cat

         A=New Cat

                B=A

  •   Basic Example

          the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors).Then, the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.

-----------------------------------------------------------

  • Attributes and Operations(Method)
    • Attribute is something a class or object know
    • Method is something a class or object does.
    • Methods are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.
  • Instance
    • The instance is the actual object created at runtime
    • the Lassie object is an instance of the Dog class.
    • The set of values of the attributes of a particular object is called its state.
    • The object consists of state and the behaviour that's defined in the object's class.

OO Charecter

  • Inheritance 
    • Subclasses’ are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.
    • For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
    • Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default.
    •  Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an ‘is-a’ relationship: Lassie is a Collie. A Collie is a Dog. Thus, Lassie inherits the methods of both Collies and Dogs.

-------------------------------------------------------------

  • Encapsulation 
    • Encap is how we hide something and expose something
    • We can change it without change in code who use the class
    • Change implementation whenever want but should not change interface
    • More ready for change
    • Property to access private field
      • WriteOnly and ReadOnly Property
    • For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface

----------------------------------------------------------

  • Polymorphism 
    • Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, This helps improve code readability.
    • How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism.
    •  Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types.
    • Pointers are an example of a simple polymorphic routine that can be used with many different types of objects
REF: http://en.wikipedia.org/wiki/Object_oriented
    :Slide handout Public training course  by GF
    :www.ict.pyo.nu.ac.th/rattasakp/231221/5_1O-OConcept.ppt
-------------------------------------------------------------------