Object-oriented programming
도입됨
13:52
프로그래밍 패러다임
여기에 한 가지 과제가 있습니다: A 등급을 받은 모든 학생을 나열하십시오. 한 프로그래머는 루프를 작성합니다 — 첫 번째 레코드에서 시작하여, 등급을 확인하고, 이름을 목록에 추가하고, 이동…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| public/ˈpʌblɪk/ | Describes a class member that code outside the class can access. |
| routines/ruːˈtiːnz/ | Sections of code written to perform particular tasks within a program. |
| object/ˈɒbdʒekt/ | 객체 |
| private/ˈpraɪvət/ | Describes a class member that code outside the class cannot access directly. |
| method/ˈmeθəd/ | A defined way of performing a task or investigation; in programming, a function associated with a class or object. |
| encapsulation/ɪnˌkæpsjʊˈleɪʃn/ | 인캡슐레이션 |
| object-oriented programming/ˈɒbdʒekt ˈɔːrɪəntɪd ˈprəʊɡræmɪŋ/ | A way of designing programs using objects that combine data and methods. |
| class/klæs/ | 클래스 |
| attributes/ˈætrɪbjuːts/ | A named property or characteristic associated with an object, element or record. |
| state/steɪt/ | The saved information needed to continue a program from its current point. |
| behaviour/bɪˈheɪvjə/ | The actions an object can perform through its methods. |
| instance/ˈɪnstəns/ | 인스턴스 |
| visibility/ˌvɪzɪˈbɪlɪti/ | The rules that control where a class member can be accessed. |
| constructor/kənˈstrʌktə/ | 생성자 |
| getters | Methods that allow other code to read an object's attribute values. |
| setters | Methods that allow other code to change an object's attribute values. |
| get methods | Methods that allow other code to read an object's attribute values. |
| set methods | Methods that allow other code to change an object's attribute values. |
| Inheritance/ɪnˈherɪtəns/ | An is-a relationship. |
| subclass/ˈsʌbklæs/ | 하위 클래스 |
| superclass/ˈsuːpəklæs/ | 상위 클래스 |
| overriding/ˌəʊvəˈraɪdɪŋ/ | Providing a subclass implementation of an inherited instance method with a matching signature, subject to the language's rules. |
| Polymorphism/ˈpɒlɪmɔːfɪzəm/ | The same call behaving differently per class, which is what lets a new subclass be added without changing existing code. |
| Abstraction/əbˈstrækʃn/ | Representing essential features while leaving out unnecessary detail. |
| method call | An instruction that asks an object to perform one of its methods. |
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| list/lɪst/ | A collection of items arranged in a particular order. |
| interface/ˈɪntəfeɪs/ | A way for users or programs to communicate with the computer's hardware. |
| is-a relationship | |
| Containment/kənˈteɪnmənt/ | An object holds another object as one of its attributes. |
| aggregation/ˌæɡrɪˈɡeɪʃn/ | 응집 |
| references/ˈrefrənsɪz/ | Values that identify objects so that code can access them. |
| collection/kəˈlekʃn/ | A group of items stored together so they can be managed and used. |
| string/strɪŋ/ | A sequence of characters treated as a single data value. |
| composition/ˌkɒmpəˈzɪʃn/ | A relationship where an object contains parts that depend on it to exist. |
| members | The attributes and methods that belong to a class or object. |
A change in one place that used to mean a change in fifty
- 프로그램이 고객의 잔고를 공개 숫자로 저장합니다. 스물 개의 routine이 읽고 십오 개가 씁니다. 이제 잔고는 절대 음수가 되어서는 안 됩니다.
- 객체가 없으면, 이 규칙은 십오개 위치에 추가되어야 하며, 누군가가 열여섯 번째 쓰기를 추가하는 날, 규칙은 다시 깨지게 됩니다.
- 객체에서 잔고는 비공개이며, 이를 변경하는 유일한 방법은 규칙을 강제하는 메서드입니다. 이를 추가할 수 있는 곳은 하나뿐이고 우회할 길은 없습니다.
- 이것이 캡슐화이며, 객체 지향 프로그래밍이 존재하는 이유입니다. 이 수업에서는 객체, 클래스, 그리고 네 가지 기둥에 대해 다룹니다.

객체와 클래스
- 객체는 데이터인 속성(attributes) 과 해당 데이터를 조작하는 메서드(methods) 를 결합합니다. 이는 상태와 행동이 통합된 단위입니다.
- 클래스(class) 는 설계도(blueprint)입니다. 그 종류의 모든 객체가 가질 속성과 메서드를 정의합니다. 객체는 고유의 값을 가진 클래스의 인스턴스(instance) 입니다.
- 하나의
Taxi클래스가 있으며, 실제 택시 각각은 고유한 등록 번호와 정원을 가진 객체입니다.

위쪽에는 속성, 아래쪽에는 메서드가 있으며 가시성이 표시됨

Programming concept lab
Connect examples to the programming idea they show.
An object combines:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
An object bundles its data (attributes) with the operations (methods) that act on it.
What is the relationship between a class and an object?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
One Taxi class defines the attributes and methods; each actual taxi is an object with its own capacity and registration.
생성자, getter 및 setter
- 생성자(constructor) 는 객체가 생성될 때 실행되어 속성을 유효한 초기값으로 설정하는 특수한 메서드입니다.
- 속성은 비공개이므로, 클래스는 값을 읽기 위한 get 메서드와 값을 변경하기 위한 set 메서드를 제공합니다. '절대 음수가 될 수 없다'와 같은 규칙은 set 메서드에서 강제됩니다.
- 이것이 비공개 속성의 가치를 결정합니다: 다른 경로가 없으므로 모든 변경 시 규칙이 강제되기 때문입니다.
CLASS Taxi
PRIVATE Capacity : INTEGER
PUBLIC PROCEDURE NEW(StartCapacity : INTEGER)
Capacity ← StartCapacity
ENDPROCEDURE
PUBLIC FUNCTION GetCapacity() RETURNS INTEGER
RETURN Capacity
ENDFUNCTION
ENDCLASS

A constructor is a special method that:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The constructor initialises a new object's attributes at creation time.
기둥 1: 엔캡슐레이션(encapsulation)
- 엔캡슐레이션은 객체의 데이터가 메서드 뒤에 숨겨져 있음을 의미합니다. 속성은 비공개이며, 외부 코드는 공개 메서드를 사용합니다.
- 두 가지 이점이 있으며, 시험에서는 둘 다 요구합니다: 객체는 모든 변경 시 자신만의 규칙을 강제할 수 있고, 내부 구현은 나중에 안전하게 변경할 수 있습니다. 왜냐하면 외부 코드에 의존하지 않기 때문입니다.
- 오늘 파운드로 잔고를 저장하고 내일 펜니로 저장하더라도, 클래스의 모든 사용자는 여전히
GetBalance()를 호출하며 외부 코드는 깨지지 않습니다.
Encapsulation means:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Encapsulation hides the data; outside code uses the public methods, so internals can change safely.
What does encapsulation buy? Select 모든 that apply.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Encapsulation is about maintainability and correctness, not speed. Private data with public methods is what makes both possible.
기둥 2: 상속(inheritance)
- 상속은 하위 클래스를 상위 클래스의 속성과 메서드를 모두 물려받아 자신의 것만 추가하거나 오버라이딩하도록 정의할 수 있게 합니다.
- 'is-a' 관계를 모델링합니다: 매니저는 사원이므로,
Manager는Employee에서 상속받아 부서를 추가합니다. - 장점은 공유 코드가 슈퍼클래스에 한 번만 작성되며, 그에 대한 변경이 모든 서브클래스에 반영된다는 점입니다.

공유되는 부분은 위에, 차이는 아래에 위치함

Inheritance models an "is-a" relationship (a Manager is an Employee), so a subclass inherits and extends its superclass.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Inheritance is "is-a" specialisation; "has-a" relationships are modelled by composition instead.
Inheritance models an "____ a" relationship, such as a Manager being an Employee.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A car has an engine, which is composition rather than inheritance. Getting that distinction right is what the question tests.
기둥 3 및 4: 다형성(polymorphism)과 추상화(abstraction)
- 다형성은 서로 다른 객체가 동일한 메서드 호출에 각자의 방식으로 반응함을 의미합니다. 모든
Shape는Area()메서드를 가집니다;Circle와Rectangle은 이를 다르게 구현합니다. - 가치: 코드는 각 객체가 어떤 종류인지 알거나 신경 쓰지 않고 shape 목록을 순환하며 각 객체에
Area()를 호출할 수 있습니다. 나중에Triangle클래스를 추가해도 그 루프는 전혀 변경할 필요가 없습니다. - 추상화는 간단한 인터페이스를 제시하고 그 뒤에 복잡성을 숨기는 것입니다:
Area()의 호출자는 기하학에 관해 아무것도 알 필요 없습니다.

Polymorphism allows:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The same call (e.g. Area()) behaves correctly for each type — the caller need not know the exact class.
Put the consequences of polymorphism in order, from the definition to the benefit.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
One call, several implementations, and the code that uses it never has to know about the new ones.
worked example: 기둥 이름 붙이기
- 어떤
BankAccount클래스는 내부 평형을 비공개로 유지하며, 이를 음수가 되도록 하지 않는Deposit()및Withdraw()메서드를 제공합니다. 인캡슐레이션: 데이터는 숨겨져 있으며, 그에게 접근할 수 있는 유일한 경로를 통해 규칙이 강제됩니다. - 이자율을 추가하여 정의된
BankAccount의SavingsAccount클래스. 상속: is-a 관계이며, 슈퍼클래스의 코드를 재사용함. - 루프가 목록의 모든 문서에
Print()를 호출하고, 각 유형이 스스로를 다르게 출력함. 다형성: 하나의 호출, 여러 구현.* - 시나리오에서 이를 보여주는 특징과 함께 기둥을 명명하십시오.

Match each OOP pillar to its meaning.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Encapsulation = hiding; inheritance = is-a specialisation; polymorphism = same interface, varied behaviour.
worked example: 대규모 시스템에 OOP를 사용하는 이유
- 대규모 시스템에 객체 지향 프로그래밍을 사용하는 두 가지 이점을 설명하십시오. [4]
- 엔캡슐레이션은 각 클래스의 내부 구조를 변경해도 프로그램의 나머지 부분에 영향을 주지 않으므로, 시스템을 유지보수하기 쉬워지고 팀이 병행하여 클래스를 작업할 수 있습니다.
- 상속은 공유 행동을 한 번 작성하여 재사용하므로, 중복 코드가 적어지고 수정이 한 번에 모든 곳에서 적용됩니다.
- 다형성은 새로운 타입을 추가해도 이를 사용하는 코드를 변경할 필요가 없습니다. 각 답변은 특징과 그 결과를 모두 포함해야 합니다.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
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 Team stores references to Player objects. Players remain when the team is removed. Which relationship fits?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The team contains independent Player objects. Inheritance would require an is-a relationship.
풀이된 예제: 선수들을 복사하지 않고 팀 디자인하기
- 알다:
Player은 비공개 이름과GetName()메서드를 가짐.Team을 설계할 때 비공개 컬렉션Members에Player객체에 대한 참조를 포함하고, 참조를 추가하는AddPlayer(NewPlayer)메서드를 정의하십시오. Player은 팀보다 먼저 존재할 수 있으며, 팀은 제거될 수 있지만 선수는 남아있음. 이는 조합(aggregation)임. 선수 자체의 메서드를 통해 선수 이름을 변경하면 해당 선수를 보유한 모든 객체에 보임; 복사된 이름 문자열은 더 이상 유효하지 않게 됨.
Player object: name = "Sam"
Team object: Members = [reference to Sam's Player object]
Goalkeeper class: inherits the Player attributes and methods
In this design, removing a Team must also destroy every Player it contains.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The Players exist independently. Removing the team removes its references, not necessarily the Player objects.
Match each design to its relationship.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Inheritance models is-a; aggregation models has-a with independent objects; encapsulation controls access to data.
놓칠 수 있는 점
- 클래스는 설계도이고, 객체는 그 인스턴스입니다. 이 두 단어를 혼용하여 사용하지 마십시오.
- 엔캡슐레이션은 메서드 뒤에 데이터를 숨기는 것이며, 그 이점은 규칙 강제와 안전한 내부 변경입니다. "더 안전하다"라는 말은 너무 모호합니다.
- 상속은 is-a 관계입니다. 자동차는 엔진을 가지고(has a) 있는데, 이는 구성(composition)이지 상속이 아닙니다.
- 다형성은 동일한 호출이 클래스마다 다르게 동작하는 것인데, 이것이 기존 코드를 변경하지 않고 새로운 서브클래스를 추가할 수 있게 합니다.
이해했습니다
- 객체는 속성과 메서드를 결합하며, 클래스는 설계도이고 객체는 생성자에 의해 설정된 인스턴스입니다.
- 엔캡슐레이션: 공개 메서드 뒤에 비공개 데이터를 두어, 모든 변경 시 규칙이 강제되고 내부 구조가 안전하게 변경될 수 있음
- 상속: 서브클래스가 슈퍼클래스의 멤버를 가져와 추가하거나 오버라이딩하며, is-a 관계를 모델링하고 공유 코드를 한 번 작성함
- 다형성: 동일한 호출이 클래스마다 다르게 구현되므로 새로운 타입은 기존 코드의 변경이 필요 없음; 추상화: 복잡성을 숨기는 간단한 인터페이스
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.