Upload
jun-shimizu
View
2
Download
1
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
Object Oriented Programming
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).
The Basics : Object
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
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?
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
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
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
Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.
Polymorphism
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
Objective-C
@interface Forwarder : Object { id someFields; } - (id) someMethod; @end
Interface Example
PHP
interface InterfaceExample { public function doSomething(); public function doEverything(); }
Interface Example
Java
interface Animal{ void eat(String what); void sleep(int time); void mate(String withWho); }
Interface Example
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
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
PHP : abstract class AbstractExample { public $name; public function doThis() { // do this } abstract public function doThat(); }
Abstract Class Example