pemrograman berorientasi objek

8
Pemrograman Berorientasi Objek Bab 5 – Package & Interface

Upload: darius-pope

Post on 30-Dec-2015

32 views

Category:

Documents


2 download

DESCRIPTION

Pemrograman Berorientasi Objek. Bab 5 – Package & Interface. Package. A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Pemrograman Berorientasi Objek

Pemrograman Berorientasi Objek

Bab 5 – Package & Interface

Page 2: Pemrograman Berorientasi Objek

Package

A package is a namespace that organizes a set of related classes and interfaces.

Conceptually you can think of packages as being similar to different folders on your computer.

You might keep HTML pages in one folder, images in another, and scripts or applications in yet another.

Page 3: Pemrograman Berorientasi Objek

Purpose

Organization.Because software written in the

programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.

Page 4: Pemrograman Berorientasi Objek

Interface

is a class like constructs that only contains constants and abstract methods.

Purpose: define constants and abstract methods (that should be implemented by class) that can be used by several class.

So interface is like contract between class and interface.

Page 5: Pemrograman Berorientasi Objek

Constant and Method in Interface

Each constant in an interface is public static final by default, so we don’t need to write it.

Each method in an interface is public abstract by default.

Page 6: Pemrograman Berorientasi Objek

Interface Rule

Can’t be instantiate. Can be used as data type. Implemented not inherited by class. Can be inherited by other interface. A class can implement many interfaces not

like inheritance (a class only inherits a class). Each method in interface MUST be

implemented by class that implement the interface.

Page 7: Pemrograman Berorientasi Objek

Warning

Since a class can inherit multiple interface, beware of name collision.

Name collision is same name (for constant or method) in different interface but implemented by a class.

Try to avoid it.

Page 8: Pemrograman Berorientasi Objek

How To?

<modifier> interface <Name> {}Show sample!!