What’ a Class?
What’s an Object?
an object is an instance of a class
OOP Key Features
- Abstraction (추상화) 7장
- Encapsulation (캡슐화) 7장
- Inheritance (상속) 8장
- Polymorphism (다형성) 9장
Abstraction
개념적 -> 논리적 -> 물리적 모델링
abstraction is selective ignorance
Decide what is important and what is not
loosely coupled – 느슨하게 연결된
Encapsulation
abstraction을 코드화
the principle of protecting sensitive parts of your objects from external manipulation
Hides the implementation details of a class
members can be public or private
클래스 속 변수는 private – Java Bean에 규칙에 똑같이 적용됨.
example)
UML Diagram
- : private
+ : public
Restricting Data Access
Use modifiers to restrict data access:
- public
Everyone can use that part of the object
- private
No one outside the object’s class can use that part of the object
Implementing Encapsulation
Methods are public, accessible from the outside
Data is private, accessible only from the inside
get Methods and set Methods
The this Reference
The this keyword means “reference” to the same object
- this. – 나의
- this – 나 자체
- this() -
나는 this 부모는 super
1. this.
명시적으로 구분할 때 this. 를 사용
멤버변수와 지역변수를 구분할 때
2. this
나 전체를 return할 때
Creating Objects
step1 : Allocating memory
step2 : Initializing the object by using a constructor
Explicit Member Initialization
명시적 초기화
int num = 5;
Constructors
- are special methods.
- have no return type
- have the same name as the class name
- are called each time you create an object
- you have been using a default constructor throughout most of the course
- default constructor
Default Constructors
all classes must have at least one constructor
the compiler provides a default constructor to any class which does not have an explicit constructor
feature
- public accessibility
- same name as the class
…
If a class has no constructor, a default constructor is inserted.
Overriding the Default Constructor (기본생성자의 재정의)
The default constructor might be inappropriate
내일은 7장 마무리
this()
생성자에 대한 이야기
student class 나눠서 파일처리
sorting까지.
Project
documentation 70% / 개인코딩 10% / 디버깅 20%
도서추천
UMl도서