Inheritance

Entities do not exist in isolation. They have some type of relationship with each other. Similarly, in C#, the classes in a program can be related to each other. Identifying and establishing relationships between classes is a critical aspect of OOP. This chapter identifies the relationship between classes. It discusses the use of classes and inheritance. In addition, this chapter discusses the use of abstract classes, sealed classes, and interfaces. | Inheritance Chapter 8 Entities do not exist in isolation. They have some type of relationship with each other. Similarly in C the classes in a program can be related to each other. Identifying and establishing relationships between classes is a critical aspect of OOP. This chapter identifies the relationship between classes. It discusses the use of classes and inheritance. In addition this chapter discusses the use of abstract classes sealed classes and interfaces. Objectives In this chapter you will learn to fl Identify relationships between classes fl Use classes and inheritance fl Use abstract classes fl Use sealed classes fl Use interfaces Identifying Relationships Between Classes In software application classes and objects are related to each other. They act and react with other classes and objects. Depicting their dynamism in an application makes the application as close as possible to the real world. In the object-oriented approach objects perform actions in response to messages from other objects defining the receiving object s behavior. This approach specifies the relationships among classes based on the behavior of individual class. Consider the similarities and differences among the objects or classes including an automobile a car a driver and an engine. You can make the following observations A truck is a kind of an automobile. A car is another kind of an automobile. An engine is a part of an automobile. A driver drives a car. Based on the preceding observations you can identify the relationships among the objects and classes. Kinds of Relationships There are various relationships between objects of different classes in an object-oriented environment Inheritance relationship Composition relationship Utilization relationship Instantiation relationship Inheritance Relationship OOP enables classes to inherit commonly used state and behavior from other classes. Consider the following example Automobile is the superclass of a car and a bus. Car and bus .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.