pemrograman berorientasi objek
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 PresentationTRANSCRIPT
![Page 1: Pemrograman Berorientasi Objek](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/1.jpg)
Pemrograman Berorientasi Objek
Bab 5 – Package & Interface
![Page 2: Pemrograman Berorientasi Objek](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/2.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/3.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/4.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/6.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/7.jpg)
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](https://reader035.vdocuments.net/reader035/viewer/2022072013/56812c61550346895d90f3fe/html5/thumbnails/8.jpg)
How To?
<modifier> interface <Name> {}Show sample!!