tailieunhanh - Object-Oriented Programming: Intefaces

Object-Oriented Programming: Inteface's Content is Defining an interface, Implementing an interface, Using an interface as a type, Rewriting interfaces; Interfaces are used to encode similarities which the classes of various types share but do not necessarily constitute a class relationship. | Lecture 4: Interfaces Lê Hồng Phương phuonglh@ Department of Mathematics, Mechanics and Informatics, Vietnam National University, Hanoi Content ● Defining an interface ● Implementing an interface ● Using an interface as a type ● Rewriting interfaces ● Examples 2012-2013 Object-Oriented Programming: Intefaces 2 Defining an interface ● ● Interfaces are used to encode similarities which the classes of various types share but do not necessarily constitute a class relationship. Examples: – A human and a parrot can both whistle. It does not make sense to represent Human and Parrot as subclasses of Whistle. – A person and a rectangle can both measurable by some criterion (., by weight for persons, by area for rectangles). 2012-2013 Object-Oriented Programming: Intefaces 3 Defining an interface ● ● In object-oriented languages, an interface is an abstract type that is used to specify an interface (in the generic sense of the term). An interface contains only – method signatures (prototypes) – constant declarations A purely abstract method. public interface Relatable { public int isLargerThan(Relatable other); } Note the semicolon 2012-2013 Object-Oriented Programming: Intefaces 4 Defining an interface ● An interface can extends others: public interface GroupedInterface extends Interface1, Interface2, Interface3 { double E = ; void doSomething(int i, double x); int doSomthingElse(String s); } A constant Two method signatures How many method signatures does the GroupedInterface have? 2012-2013 Object-Oriented Programming: .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.