tailieunhanh - Encapsulation-Important Principle

The Purpose of Encapsulation Encapsulation is an important principle when defining classes. The idea is that a program that uses a class should not have to worry how that class actually works internally | The Purpose of Encapsulation Encapsulation is an important principle when defining classes. The idea is that a program that uses a class should not have to worry how that class actually works internally the program simply creates an instance of a class and calls the methods of that class. As long as those methods do what they say they will do the program does not care how they are implemented. For example when you call the method you don t want to be bothered with all the intricate details of how the Console class physically arranges for data to be output to the screen. A class might need to maintain all sorts of internal state information in order to perform its various methods. This additional state information and activity is hidden from the program that is using the class. Therefore encapsulation is sometimes referred to as information-hiding. Encapsulation actually has two purposes 1. To combine methods and data inside a class in other words to support classification. 2. To control the accessibility of the methods and data in other words to control the use of the class. Understanding Classification Class is the root word of classification. When you design a class you systematically arrange information into a meaningful entity. This arranging is an act of classification and is something that everyone does not just programmers. For example all cars share common behaviors they can be steered stopped accelerated and so on and common attributes they have a steering wheel an engine and so on . People use the word car to mean objects that share these common behaviors and attributes. As long as everyone agrees on what a word means it all works well you can express complex but precise ideas in a concise form. Without classification it s hard to imagine how people could think or communicate at all. Given that classification is so deeply ingrained into the way we think and communicate it makes sense to try to write programs by classifying the different

TÀI LIỆU LIÊN QUAN
10    127    1
6    150    1
7    127    1
5    125    1
6    127    1
6    115    1
6    122    1
6    174    1
7    122    1
crossorigin="anonymous">
Đã 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.