| English | 의미 |
|---|---|
| object/ˈɒbdʒekt/ | 객체 |
| encapsulation/ɪnˌkæpsjʊˈleɪʃn/ | 인캡슐레이션 |
| class/klæs/ | 클래스 |
| instance/ˈɪnstəns/ | 인스턴스 |
| constructor/kənˈstrʌktə/ | 생성자 |
| inheritance/ɪnˈherɪtəns/ | 상속 |
| subclass/ˈsʌbklæs/ | 하위 클래스 |
| superclass/ˈsuːpəklæs/ | 상위 클래스 |
| polymorphism/ˈpɒlɪmɔːfɪzəm/ | 다态 |
| abstraction/əbˈstrækʃn/ | 추상화 |
| containment/kənˈteɪnmənt/ | 포함 |
| aggregation/ˌæɡrɪˈɡeɪʃn/ | 응집 |
A change in one place that used to mean a change in fifty
- A program stores a customer's balance as a public number. Twenty routines read it and fifteen write it. Now the balance must never go negative.
- Without objects, that rule has to be added at fifteen places, and the day someone adds a sixteenth writer it is broken again.
- With objects, the balance is private and the only way to change it is a method that enforces the rule. There is one place to add it and no way round it.
- That is encapsulation 封装, and it is the reason object-oriented programming exists. This lesson is objects, classes 类, and the four pillars.
Objects and classes
- An object 对象 combines attributes, its data, with methods, the operations that act on that data. It is a unit of state and behaviour together.
- A class is the blueprint: it defines what attributes and methods every object of that kind will have. An object is an instance 实例 of a class, with its own values.
- One
Taxiclass, and each actual taxi is an object with its own registration and capacity.

Attributes above, methods below, and their visibility marked
프로그래밍 개념 실습
각 예시가 나타내는 프로그래밍 개념에 연결하십시오.
객체는 다음을 결합합니다:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
객체는 데이터(속성)와对它 작용하는 연산(메소드)을 묶습니다.
클래스와 객체의 관계는 무엇입니까?
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
One Taxi class는 속성과 메소드를 정의하며; 실제 택시는 각기 다른 수용량과 등록 번호를 가진 객체입니다.
Constructors, getters and setters
- A constructor 构造函数 is a special method that runs when an object is created, to set up its attributes to valid initial values.
- Because attributes are private, a class provides get methods to read a value and set methods to change one. A set method is where a rule such as "never negative" is enforced.
- That is what makes the private attribute worth having: the rule is enforced on every change, because there is no other route to the data.
CLASS Taxi
PRIVATE Capacity : INTEGER
PUBLIC PROCEDURE NEW(StartCapacity : INTEGER)
Capacity ← StartCapacity
ENDPROCEDURE
PUBLIC FUNCTION GetCapacity() RETURNS INTEGER
RETURN Capacity
ENDFUNCTION
ENDCLASS
생성자(constructor)는 다음과 같은 특수 메소드입니다:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
생성자는 객체가 생성될 때 새로운 객체의 속성을 초기화합니다.
Pillar 1: encapsulation
- Encapsulation means an object's data is hidden behind its methods. Attributes are private; outside code uses the public methods.
- Two benefits, and the exam wants both: the object can enforce its own rules on every change, and the internal representation can be changed safely later, because no outside code depends on it.
- Store the balance in pounds today and in pennies tomorrow: every user of the class still calls
GetBalance()and nothing outside breaks.
encapsulation(캡슐화)은 다음을 의미합니다:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
캡슐화는 데이터를 숨깁니다; 외부 코드는 public 메소드를 사용하므로 내부 구조를 안전하게 변경할 수 있습니다.
캡슐화가 제공하는 이점을 모두 선택하십시오.
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
인캡슐화는 속도가 아니라 유지보수성과 정확성에 관한 것입니다. 공개된 메서드를 가진 비공개 데이터가 이 둘 모두를 가능하게 합니다.
Pillar 2: inheritance
- Inheritance 继承 lets a subclass 子类 be defined in terms of a superclass 父类, taking all its attributes and methods and then adding its own or overriding them.
- It models an "is-a" relationship: a Manager is an Employee, so
Managerinherits fromEmployeeand adds a department. - The benefit is that shared code is written once in the superclass, and a change to it reaches every subclass.

The shared part lives above; the differences live below
상속은 "is-a" 관계를 모델링합니다(매니저는 종업원입니다). 따라서 하위 클래스는 상위 클래스를 상속하여 확장합니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
상속은 "is-a" 특화입니다. "has-a" 관계는 대신 합성(composition)으로 모델링됩니다.
상속은 매니저가 종업원이라는 것과 같은 "____ a" 관계를 모델링합니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
자동차에는 엔진이 있으며, 이는 상속이 아닌 합성입니다. 이 구분을 올바르게 하는 것이 문제의 의도입니다.
Pillars 3 and 4: polymorphism and abstraction
- Polymorphism 多态 means different objects respond to the same method call in their own way. Every
Shapehas anArea()method;CircleandRectangleeach implement it differently. - Its value: code can loop over a list of shapes calling
Area()on each, without knowing or caring which kind each one is. Add aTriangleclass later and that loop needs no change at all. - Abstraction 抽象 means showing a simple interface and hiding the complexity behind it: the caller of
Area()need not know any geometry.
다형성이 허용하는 것은:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
동일한 호출(Area() 등)이 각 유형에 대해 올바르게 작동하며, 호출자는 정확한 클래스를 알 필요는 없습니다.
정의부터 혜택까지 다형성의 결과를 순서대로 나열하십시오.
난이도 3/5 · 200 코인 + 오늘 첫 완료 시 소액 보너스
한 개의 호출, 여러 가지 구현 방식, 그리고 이를 사용하는 코드는 새 implementations에 대해 절대 알 필요 없습니다.
Worked example: name the pillar
- A
BankAccountclass keeps its balance private and providesDeposit()andWithdraw()methods that refuse to make it negative. Encapsulation: the data is hidden and the rule is enforced by the only routes to it. - A
SavingsAccountclass is defined as aBankAccountwith an added interest rate. Inheritance: an is-a relationship, reusing the superclass's code. - A loop calls
Print()on every document in a list, and each type prints itself differently. Polymorphism: one call, several implementations. - Name the pillar and the feature of the scenario that shows it.
각 OOP의 기둥과 그 의미를 매칭하십시오.
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
인캡슐레이션 = 숨기기; 상속 = is-a 특화; 다형성 = 동일한 인터페이스, 다양한 행동.
Worked example: why OOP for a large system
- Give two advantages of using object-oriented programming for a large system. [4]
- Encapsulation means each class's internals can be changed without affecting the rest of the program, so the system is easier to maintain and a team can work on classes in parallel.
- Inheritance means shared behaviour is written once and reused, so there is less duplicated code and a fix applies everywhere at once.
- Polymorphism means new kinds can be added without changing the code that uses them. Each answer is a feature and its consequence.
A team has players; it is not a player
- Containment 包含 means an object holds another object as one of its attributes. In aggregation 聚合, the contained object can exist independently: a
Teamholds references toPlayerobjects that can move to another team. - Choose by the relationship: a
Goalkeeperis aPlayer, so use inheritance; aTeamhas players, so use aggregation. A team inheriting a player'sKick()method is a design error, even if the team would enjoy taking a penalty.
A 팀은 Player 객체에 대한 참조를 저장합니다. 팀이 삭제되어도 Player는 유지됩니다. 어떤 관계가 적합합니까?
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
팀에는 독립적인 Player 객체가 포함되어 있습니다. 상속은 'is-a' 관계를 요구합니다.
Worked example: design a team without copying its players
- Known: a
Playerhas a private name and aGetName()method. DesignTeamwith a private collectionMemberscontaining references toPlayerobjects and anAddPlayer(NewPlayer)method that adds a reference. - A
Playercan exist before the team, and a team can be removed while its players remain. This is aggregation. Changing a player's name through the player's own method is visible to every object holding that player; a copied name string would become stale.
Player object: name = "Sam"
Team object: Members = [reference to Sam's Player object]
Goalkeeper class: inherits the Player attributes and methods
이 디자인에서 팀을 제거하면 해당 팀이 포함하는 모든 Player도 파괴되어야 합니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
Player는 독립적으로 존재합니다. 팀을 제거하면 그 참조만 제거할 뿐, 반드시 Player 객체를 삭제하지는 않습니다.
각 디자인을 그에 맞는 관계와 매칭하십시오.
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
상속은 'is-a'를 모델링하고, 집합은 독립적 객체의 'has-a'를 모델링하며, 캡슐화는 데이터 접근을 제어합니다.
Marks that slip away
- A class is the blueprint, an object is an instance of it. Do not use the words interchangeably.
- Encapsulation is hiding data behind methods, and its benefits are rule enforcement and safe internal change. "It is more secure" is too vague.
- Inheritance is an is-a relationship. A car has a engine, which is composition, not inheritance.
- Polymorphism is the same call behaving differently per class, which is what lets a new subclass be added without changing existing code.
You've got it
- an object combines attributes and methods; a class is the blueprint and an object is an instance, set up by a constructor
- encapsulation: private data behind public methods, so rules are enforced on every change and internals can change safely
- inheritance: a subclass takes a superclass's members and adds or overrides them, modelling is-a and writing shared code once
- polymorphism: the same call implemented differently per class, so new kinds need no change to existing code; abstraction: a simple interface hiding the complexity