15
Object Oriented Programming Lecture by Niko Adrianus Yuwono

Object oriented programming

Embed Size (px)

DESCRIPTION

PT.BUZOO INDONESIA is No1 Japanese offshore development company in Indonesia. We are professional of web solution and smartphone apps. We can support Japanese, English and Indonesia. We are hiring now at http://buzoo.co.id/

Citation preview

Page 1: Object oriented programming

Object Oriented Programming

Lecture by Niko Adrianus Yuwono

Page 2: Object oriented programming

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). 

The Basics : Object

Page 3: Object oriented programming

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.

Cont’d

Page 4: 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.

Class : What Is a Class?

Page 5: Object oriented programming

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

Class : Inheritance

Page 6: Object oriented programming

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.

Cont’d

Page 7: Object oriented programming

This is a table of access member control that define which member of the class can be accessed

Class : Access Member Control

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

Page 8: Object oriented programming

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

Polymorphism

Page 9: Object oriented programming

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.

Interface

Page 10: Object oriented programming

Objective-C

@interface Forwarder : Object { id someFields; } - (id) someMethod; @end

Interface Example

Page 11: Object oriented programming

PHP

interface InterfaceExample { public function doSomething(); public function doEverything(); }

Interface Example

Page 12: Object oriented programming

Java

interface Animal{ void eat(String what); void sleep(int time); void mate(String withWho); }

Interface Example

Page 13: Object oriented programming

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).

Overloading and Overriding

Page 14: Object oriented programming

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.

Abstract Class

Page 15: Object oriented programming

PHP : abstract class AbstractExample {       public $name;       public function doThis() {           // do this       }       abstract public function doThat();     }  

Abstract Class Example