Академический Документы
Профессиональный Документы
Культура Документы
Oum Saokosal, Head of IT Department National Polytechnic Institute of Cambodia Tel: (855)-12-417214 E-mail: oum_saokosal@yahoo.com
1
Interface
Interface
What is interface? How to define interface? How to use interface? Why not use abstract class instead of interface? UML of interface Importance of interface Different between interface and abstract class Notes for interface Class Design Guidline Last words
3
What is Interface?
In many ways, Interface is very similar to abstract class but it marks with interface keyword instead of abstract class keyword.
/* Constant declarations */ /* Method signatures */ } E.g: public interface Moveable{ final int MAX_MOVE = 20; final int MIN_MOVE = 1; public void move(); }
5
final int MAX_MOVE = 20; final int MIN_MOVE = 1; public String howToMove(); }
public class King
implements
Moveable{
@Override
public String howToMove(){ return One step to every direction; } }
7
Not at all, Ball. GUI is GUI. Interface here is a kind of ideas in OOP which is similar to abstract class. Ill tell ya what...
10
13
14
16
} CB: Wow, wonderful. Now I know why we use interface instead of abstract class.
18
Interface
20
21
Fish
public interface Moveable{ //Constants final int MAX_MOVE = 20; final int MIN_MOVE = 1; //abstract methods public String howToMove(); }
23
24
2. Interface uses interface keyword. 3. Interface is NOT designed to be superclass. Interface is designed to add some behaviors to a 25 class.
26
p. 358-360
1. A class should descript a single entity or a single thing. 2. Classes are usually designed for reuse by many different customers and developers. 3. If we want polymorphism, you have to use inheritance design (of course, overridden method). 4. If NO need polymorphism, use composite design. 5. If a relationship is strong like apple and fruit, please use abstract class design. 6. If a relationship is weak like apple and eatable, please use interface design.
29
30
33
34
Bye... Bye..
35