Object Oriented Programming - Lesson 5: Encapsulation, Overloading and Aggregation

Object Oriented Programming - Lesson 5: Encapsulation, Overloading and Aggregation includes Encapsulation (Visibility scope, Data hiding), Overloading (Principles, Constructor overloading), Aggregation (Principles, Order of initialization). | LESSON V. Encapsulation, Overloading and Aggregation Trinh Thanh TRUNG (MSc) trungtt@ Content • Encapsulation – Visibility scope – Data hiding • Overloading – Principles – Constructor overloading • Aggregation – Principles – Order of initialization • Class usage – Any classes – Java classes I. Encapsulation • Encapsulation: Prevents the code and data being randomly accessed by other code defined outside the class. – Group data and operations performed on these data together in a class – Hide details about the class implementation from the user. 4 1. Visibility scope (revisited) • Scope determines the visibility of program elements with respect to other program elements. • Given a class: – A private attribute or operation of an object is accessible by all others objects of the same class – A public attribute or operation of an object is accessible by all others objects. X getAuthorName private public Vu Thi Huong Giang Object outside the class Book Object MyBook If an attribute or operation is declared private, it cannot be accessed by anyone outside the class 5 2. Data hiding • A class provides data hiding – Data is in a unique scope; access controlled with public, private, protected keywords – Data is accessed through public methods; a collection of the signatures of public methods of a class is called interface. Avoid illegal modification of attributes Public .

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
94    67    2    04-07-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.