Encapsulation and Abstraction

Objects contain data and methods to send and receive messages. Data members of objects can have a different scope or visibility. You use access specifier to define the scope of data member and method. This chapter introduces the concept of abstraction and encapsulation. It discusses the implementation of encapsulation by using access specifiers. It also explains the concept of using methods. In addition, the chapter also discusses the static variables and static functions. | Encapsulation and Abstraction Chapter 4 Objects contain data and methods to send and receive messages. Data members of objects can have a different scope or visibility. You use access specifier to define the scope of data member and method. This chapter introduces the concept of abstraction and encapsulation. It discusses the implementation of encapsulation by using access specifiers. It also explains the concept of using methods. In addition the chapter also discusses the static variables and static functions. Objectives In this chapter you will learn to fl Define abstraction and encapsulation fl Implement encapsulation by using access specifiers fl Use methods fl Use static variables and static functions Introducing Abstraction and Encapsulation Abstraction and encapsulation are important features of any OOPs language. Abstraction involves extracting only the relevant information. Encapsulation involves packaging one or more components together. Defining Abstraction Consider the following example An automobile salesperson is aware that different people have different preferences. Some people are interested in the speed of a car some in its price some in the engine and the some in its style. Although all of them want to buy a car each of them is interested in a specific attribute or feature. The salesman knows all the details of a car but he presents only the relevant information to a potential customer. As a result the salesman practices abstraction and presents only relevant details to customer. In other words abstraction means looking for what you want in an object or a class. Consider abstraction from the perspective of a programmer who wants a user to be able to add items to a list. However the detail of how a particular task in a program is accomplished is hidden. Abstraction does not mean that information is unavailable. It means that all the information exists but only the relevant information is provided to the user. Defining Encapsulation Encapsulation .

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.