TAILIEUCHUNG - Lecture 4: Interface Design

Tham khảo bài thuyết trình 'lecture 4: interface design', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Lecture 4: Interface Design concept An interface is a way to describe what classes should do, without specifying how they should do it. It’s not a class but a set of requirements for classes that want to conform to the interface . public interface Comparable { int compareTo(Object otherObject); } this requires that any class implementing the Comparable interface contains a compareTo method, and this method must take an Object parameter and return an integer Interface declarations The declaration consists of a keyword interface, its name, and the members Similar to classes, interfaces can have three types of members constants (fields) methods nested classes and interfaces Interface member – constants An interface can define named constants, which are public, static and final (these modifiers are omitted by convention) automatically. Interfaces never contain instant fields. All the named constants MUST be initialized An example interface Interface Verbose { int SILENT = 0; int TERSE = 1; int NORMAL = 2; int VERBOSE = 3; void setVerbosity (int level); int getVerbosity(); } Interface member – methods They are implicitly abstract (omitted by convention). So every method declaration consists of the method header and a semicolon. They are implicitly public (omitted by convention). No other types of access modifiers are allowed. They can’t be final, nor static Modifiers of interfaces itself An interface can have different modifiers as follows public/package(default) abstract all interfaces are implicitly abstract omitted by convention To implement interfaces in a class Two steps to make a class implement an interface 1. declare that the class intends to implement the given interface by using the implements keyword class Employee implements Comparable { . . . } 2. supply definitions for all methods in the interface public int compareTo(Object otherObject) { Employee other = (Employee) otherObject; if (salary .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.