C# 2005 Programmer’s Reference - chapter 14

Tham khảo tài liệu 'c# 2005 programmer’s reference - chapter 14', 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ả | 288 CHAPTER 14 Implementing Abstract Classes and Interfaces This chapter shows how to create both abstract classes and interfaces. You ll see how both can help create interfaces for other code to use. Another important point is that you ll see how to write code that implements interfaces. Abstract Classes Abstract classes are a special type of base classes. In addition to normal class members there are abstract class members. These abstract class members are methods and properties declared without an implementation. All classes derived directly from abstract classes must implement these abstract methods and properties. You can look at an abstract class as a cross between normal classes and interfaces in that they can have their own implementation yet define an interface through abstract members that derived classes must implement. C interface types are covered later in this chapter but for right now you need to know that interfaces do not contain any implementation a fact that differentiates them from abstract classes that can have implementation. Abstract classes can never be instantiated. This would be illogical because of the members without implementations. So what good is a class that can t be instantiated Lots Abstract classes sit toward the top of a class hierarchy. They establish structure and meaning to code. They make frameworks easier to build. This is possible because abstract classes have information and behavior common to all derived classes in a framework. Take a look at the following example abstract public class Contact protected string name public Contact statements. public abstract void GenerateReport abstract public string Name get set public class Customer Contact string gender decimal income Abstract Classes 289 int numberOfVisits public Customer statements public override void GenerateReport unique report public override string Name get numberOfVisits return name set name value numberOfVisits 0 public class SiteOwner Contact int siteHits .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
5    81    2    30-06-2024
Đã 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.