Lecture by Niko Adrianus Yuwono
 Objects are key to understanding object-
oriented programming.
 Objects are like real-world objects like cat or
car
 Real-world objects share two characteristics:
They all have state and behavior.
 For example cats have state (name, color,
breed, hungry) and behavior (meowing,
fetching, wagging tail, playing).
 Same as real-world object, object in
programming also have that two
characteristics : state (fields) and behavior
(methods)
 Hiding internal state and requiring all
interaction to be performed through an
object's methods is known as data
encapsulation — a fundamental principle of
object-oriented programming.
 In the real world, you'll often find many individual
objects all of the same kind. There may be
thousands of other cats in existence, but all of
them have same state and behaviour.
 That’s why we use class to classify them.
 Objects of the same kind are said to be members
of the same class.
 Let’s say there are Angora Cat, Persian Cat and
Common Cat. All of them are members of Cat
class and they have same basic state and
behaviour.
 Furthermore, if we want to make the
classification bigger we can use Inheritance
 Imagine a class with a very big scope let’s say
we have a class named Animal that have
fields legs, isHungry, isAlive, etc and methods
eat, sleep, etc
 The attribute in the class Animal can be
inherited to their sub/child class
 For example we’ve a class named cats that
extends to animal class
 That means animal class is the parent/super
class of cats class
 Cat class will get all the same fields and
methods as animal class
 However, you must take care to properly
document the state and behavior that each
superclass defines, since that code will not
appear in the source file of each subclass.
 This is a table of access member control that
define which member of the class can be
accessed
Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N
 Polymorphism describes a pattern in object
oriented programming in which classes have
different functionality while sharing a
common interface.
 An interface is similar to a class except that it
cannot contain code. An interface can define
method names and arguments, but not the
contents of the methods.
 Any classes implementing an interface must
implement all methods defined by the
interface.
 Objective-C
 @interface Forwarder : Object
 {
 id someFields;
 }
 - (id) someMethod;
 @end
 PHP
 interface InterfaceExample {
 public function doSomething();
 public function doEverything();
 }
 Java
 interface Animal{
 void eat(String what);
 void sleep(int time);
 void mate(String withWho); }
 Method overloading deals with the notion of
having two or more methods(functions) in the
same class with the same name but different
arguments.
 While Method overriding means having two
methods with the same arguments, but
different implementation. One of them would
exist in the Parent class (Base Class) while
another will be in the derived class(Child
Class).
 An abstract class is a mix between an
interface and a class. It can define
functionality as well as interface (in the form
of abstract methods). Classes extending an
abstract class must implement all of the
abstract methods defined in the abstract
class.
 PHP :
 abstract class AbstractExample {
 public $name;
 public function doThis() {
 // do this
 }
 abstract public function doThat();
 }

Object oriented programming

  • 1.
    Lecture by NikoAdrianus Yuwono
  • 2.
     Objects arekey to understanding object- oriented programming.  Objects are like real-world objects like cat or car  Real-world objects share two characteristics: They all have state and behavior.  For example cats have state (name, color, breed, hungry) and behavior (meowing, fetching, wagging tail, playing).
  • 3.
     Same asreal-world object, object in programming also have that two characteristics : state (fields) and behavior (methods)  Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.
  • 4.
     In thereal world, you'll often find many individual objects all of the same kind. There may be thousands of other cats in existence, but all of them have same state and behaviour.  That’s why we use class to classify them.  Objects of the same kind are said to be members of the same class.  Let’s say there are Angora Cat, Persian Cat and Common Cat. All of them are members of Cat class and they have same basic state and behaviour.
  • 5.
     Furthermore, ifwe want to make the classification bigger we can use Inheritance  Imagine a class with a very big scope let’s say we have a class named Animal that have fields legs, isHungry, isAlive, etc and methods eat, sleep, etc  The attribute in the class Animal can be inherited to their sub/child class
  • 6.
     For examplewe’ve a class named cats that extends to animal class  That means animal class is the parent/super class of cats class  Cat class will get all the same fields and methods as animal class  However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.
  • 7.
     This isa table of access member control that define which member of the class can be accessed Access Levels Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y N N private Y N N N
  • 8.
     Polymorphism describesa pattern in object oriented programming in which classes have different functionality while sharing a common interface.
  • 9.
     An interfaceis similar to a class except that it cannot contain code. An interface can define method names and arguments, but not the contents of the methods.  Any classes implementing an interface must implement all methods defined by the interface.
  • 10.
     Objective-C  @interfaceForwarder : Object  {  id someFields;  }  - (id) someMethod;  @end
  • 11.
     PHP  interfaceInterfaceExample {  public function doSomething();  public function doEverything();  }
  • 12.
     Java  interfaceAnimal{  void eat(String what);  void sleep(int time);  void mate(String withWho); }
  • 13.
     Method overloadingdeals with the notion of having two or more methods(functions) in the same class with the same name but different arguments.  While Method overriding means having two methods with the same arguments, but different implementation. One of them would exist in the Parent class (Base Class) while another will be in the derived class(Child Class).
  • 14.
     An abstractclass is a mix between an interface and a class. It can define functionality as well as interface (in the form of abstract methods). Classes extending an abstract class must implement all of the abstract methods defined in the abstract class.
  • 15.
     PHP : abstract class AbstractExample {  public $name;  public function doThis() {  // do this  }  abstract public function doThat();  }