HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
객체 지향 프로그래밍
객체 지향 프로그래밍
/
객체지향의 특성
객체지향의 특성
/
💊
1. 캡슐화
💊

1. 캡슐화

1. 캡슐화 - Encapsulation

  • 완성도가 있다.
    • 객체의 속성(data fields)과 행위(메서드, methods)를 하나로 묶고 (응집성?)
    • 기능을 수행하는 단위로써 완전함을 갖는다.
    • Related Key word - class
 
  • 정보가 은닉되어 있다. - Information Hiding
    • 실제 구현 내용 일부를 내부에 감추어 은닉한다.
    • 객체의 정보가 밖으로 전달 되거나
    • 밖에서 객체 내의 정보에 접근하지 못한다.
    • Related Key word - public protected private default
    •  
❗
Note! Encapsulation is not information hiding!
 
class Human{ Heart heart; Blood blood; } Human h = new Human(); ... h.heart.stop(); // 으악!
⇒ 접근 제어자!
class Human{ private Heart heart; private Blood blood; }
⇒ 메서드 추가
class Human{ private Heart heart; private Blood blood; Blood donation() { return null; } } ... new Human().donation();

class Human{ private Heart heart; private Blood blood; protected Gene gene; Blood donation() { return null; } } class Child extends Human { void birth( ){ super.heart; // X this.heart; // X this.gene //O } }
 
  • 접근 지정자
    • private : 객체 소유
    • protected : 상속된 객체에서도 접근 가능
    • default (package-private) : 동일 패키지내 접근 가능
    • public : 접근 가능
    •