본문 바로가기
공부/Object-Oriented Design

2.4 – Encapsulation

by 혼밥맨 2021. 9. 18.
반응형

2.4 – Encapsulation

 

Besides attributes, a class also defines behaviors through methods.

For an object of the class, the methods manipulate the attribute values or data in the object to achieve the actual behaviors. 

You can expose certain methods to be accessible to objects of other classes, thus, providing an interface to use the class. 

 

Encapsulation helps with software changes. The accessible interface of a class can remain the same, while the implementation of the attributes and methods can change. 

 

Outsiders using the class, do not need to care how implementation actually works behind the interface. 

 

Advantages of Encapsulation

 - Security is increased due to restricted and controlled access to attributes and methods.

 - Changing the software is easier because related data and code are located in the same place.

 - Reusability is increased because the interface of a class can stay the same even if its internal implementation changes.

 

반응형

'공부 > Object-Oriented Design' 카테고리의 다른 글

2.6 – Generalization  (0) 2021.09.18
2.5 – Decomposition  (0) 2021.09.18
2.3 – Abstraction  (0) 2021.09.18
2.2 – Languages Evolution  (0) 2021.09.18
2.1 – Models: Bridging Concepts and Solutions  (0) 2021.09.18

댓글