What is the difference between an interface and an abstract class?

Interfaces

An interface is similar to an abstract class; indeed interfaces occupy the same namespace as classes and abstract classes. For that reason, you cannot define an interface with the same name as a class. An interface is a fully abstract class; none of its methods are implemented and instead of a class sub-classing from it, it is said to implement that interface.

An interface is a contract: The person writing the interface says, "hey, I accept things looking that way", and the person using the interface says "OK, the class I write looks that way".

An interface is an empty shell. There are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern.

Abstract classes

An abstract class is a class that is only partially implemented by the programmer. It may contain one or more abstract methods. An abstract method is simply a function definition that serves to tell the programmer that the method must be implemented in a child class.

Abstract classes, unlike interfaces, are classes. They are more expensive to use, because there is a look-up to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more: You can define a behavior for them. It's more about a person saying, "these classes should look like that, and they have that in common, so fill in the blanks!".

The key technical differences between an abstract class and an interface are:
  • Abstract classes can have constants, members, method stubs (methods without a body) and defined methods, whereas interfaces can only have constants and methods stubs.
  • Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public (they are defined public by default).
  • When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined.
  • Similarly, an interface extending another interface is not responsible for implementing methods from the parent interface. This is because interfaces cannot define any implementation.
  • A child class can only extend a single class (abstract or concrete), whereas an interface can extend or a class can implement multiple other interfaces.
  • A child class can define abstract methods with the same or less restrictive visibility, whereas a class implementing an interface must define the methods with the exact same visibility (public).
Interface are similar to abstract classes. The difference between interfaces and abstract classes are:
  • Interfaces cannot have properties, while abstract classes can
  • All interface methods must be public, while abstract class methods is public or protected
  • All methods in an interface are abstract, so they cannot be implemented in code and the abstract keyword is not necessary
  • Classes can implement an interface while inheriting from another class at the same time

 

behavior

@behavior
- (Tech) cách xử lý, chế độ; hành vi, trạng thái

define

@define /di'fain/
* ngoại động từ
- định nghĩa (một từ...)
- định rõ, vạch rõ (hình dạng, ranh giới...)
=to define the right for someone+ định rõ quyền hạn cho ai
=to define the boundary between two countries+ định rõ ranh giới hai nước
- xác định đặc điểm, chỉ rõ tính chất

@define
- định nghĩa, xác định

extend

@extend /iks'tend/
* ngoại động từ
- duỗi thẳng (tay, chân...); đưa ra, giơ ra
=to extend the arm+ duỗi cánh tay
=to extend the hand+ đưa tay ra, giơ tay ra
- kéo dài (thời hạn...), gia hạn, mở rộng
=to extend the boundaries of...+ mở rộng đường ranh giới của...
=to extend one's sphere of influence+ mở rộng phạm vi ảnh hưởng
=to extend the meaning ofa word+ mở rộng nghĩa của một từ
- (quân sự) dàn rộng ra (quân đội)
- (thể dục,thể thao), (từ lóng) làm việc dốc hết
- dành cho (sự đón tiếp...); gửi tới (lời chúc...)
=to extend hepl+ dành cho sự giúp đỡ
=to extend the best wishes to...+ gửi những lời chúc tốt đẹp nhất tới (ai...)
- (pháp lý) đánh giá (tài sản) (để tịch thu); tịch thu (tài sản, vì nợ)
- chép (bản tốc ký...) ra chữ thường
* nội động từ
- chạy dài, kéo dài (đến tận nơi nào...); mở rộng
=their power is extending more and more every day+ quyền lực của họ càng ngày càng mở rộng
- (quân sự) dàn rộng ra (quân đội)

@extend
- mở rộng; giãn; kéo dài; thác triển; khuếch

implemented

@implement /'impliment/
* danh từ
- ((thường) số nhiều) đồ dùng (đồ đạc quần áo...), dụng cụ, công cụ; phương tiện
=kitchen implements+ dụng cụ làm bếp
=the army is an implement of proletarian power+ quân đội là một công cụ của chính quyền vô sản
- (Ê-cốt) (pháp lý) sự thi hành, sự thực hiện đầy đủ (giao kèo...)
* ngoại động từ
- thi hành, thực hiện đầy đủ (giao kèo, khế ước...)
- (từ Mỹ,nghĩa Mỹ) cung cấp dụng cụ
- bổ sung

implies

@imply /im'plai/
* ngoại động từ
- ý nói; ngụ ý; bao hàm ý
=silence implies consent+ im lặng là ngụ ý bằng lòng
=do you imply that I am not telling the truth?+ ý anh muốn nói rằng tôi không kể sự thực phải không?

@imply
- bao hàm; kéo theo; có hệ quả, có nghĩa; hiểu ngầm là

inherit

@inherit /in'herit/
* ngoại động từ
- hưởng, thừa hưởng, thừa kế
* nội động từ
- là người thừa kế

@inherit
- thừa hưởng, kế tục

occupy

@occupy /'ɔkjupai/
* ngoại động từ
- chiếm, chiếm giữ
- chiếm, chiếm đóng
- giữ
=to occupy an important pasition in the government+ giữ một địa vị quan trọng trong chính phủ
- choán, chiếm cứ
=many worries occupy his mind+ nhiều nỗi lo lắng choán cả đầu óc hắn
- ở
=to occupy a house+ ở một căn nhà
- bận rộn với
=to occupy ineself with something+ bận rộn với việc gì

partially

@partially
* phó từ
- không hoàn chỉnh; cục bộ, một phần
- một cách không vô tư; thiên vị

responsible

@responsible /ris'pɔnsəbl/
* tính từ
- chịu trách nhiệm
=to be responsible for something+ chịu trách nhiệm về việc gì
- có trách nhiệm; đứng đắn, đáng tin cậy; có uy tín (người)
!responsible government
- chính phủ không chuyên quyền

restrictive

@restrictive /ris'triktiv/
* tính từ
- hạn chế, giới hạn, thu hẹp
=restrictive practices+ biện pháp hạn chế (sản xuất công nghiệp...)

signatures

@signature /'signitʃə/
* danh từ
- chữ ký
=to put one's signature to a letter+ kỹ tên vào một bức thư
- (âm nhạc) chìa (khoá) ((thường) key signature)
- (rađiô) (signature tune) điệu nhạc dạo đầu
- (ngành in) ký hiệu trang (để đóng sách cho đúng số trang)
- (từ cổ,nghĩa cổ) vẻ, dấu hiệu
=the signature of intelligence+ vẻ thông minh

@signature
- (đại số) ký số
- s. of a quadratic form ký số của một dạng toàn phương

similarly

@similarly /'similəli/
* phó từ
- cũng như thế, cũng như vậy, tương tự

@similarly
- đồng dạng

stubs

@stub /stʌb/
* danh từ
- gốc (cây)
- chân (răng)
- mẩu (bút chì, thuốc lá, đuôi chó)
- (từ Mỹ,nghĩa Mỹ) cuống (séc, hoá đơn...)
- cái nhú ra, vật nhú ra
=a mere stub of a horn+ sừng mới nhu ra được một tí
- (như) stub_nail
* ngoại động từ
- đánh gốc, đánh hết gốc (ở một khoảnh đất)
- giụi tắt (mẩu thuốc lá) ((cũng) stub out)
- vấp (ngón chân)
=to stub one's toe against something+ vấp ngón chân vào vật gì

visibility

@visibility /,vizi'biliti/
* danh từ
- tính chất có thể trông thấy được
=the visibilityof a gas+ tính chất trông thấy được của một chất khí
=high visibility+ (khí tượng) sự trông thấy rõ; tầm nhìn xa lớn
- tính rõ ràng, tính rõ rệt, tính minh bạch

whereas

@whereas /we r' z/
* liên từ
- nhưng trái lại, trong khi mà, còn
=some people like meat with much fat in it whereas others hate it+ nhiều người thích thịt mỡ trong khi mà nhiều
người khác lại ghét
- (pháp lý) bởi vì, xét rằng