Unit 2의 평가 문제를 피드백하겠습니다. Unit 2는 프로그래밍 컨셉, oop를 묻는 내용이 주를 이뤘습니다.
Q1. Describe the programming process
The programming process is an ordered list of steps or stages that is performed to produce a program.
Understand the task or problem to be performed or solved
Determine a high level strategy for performing the task or solving the problem
Elaborate the high level strategy to a detailed strategy that consists of computations that a computer can perform
Implement the computations with computer instructions
Validate that the execution of the instructions on a computer performs the task or solves the problem of step 1
Q2. Describe the steps of the programming process in terms of software engineering activities.
The programming process consists of:
requirement analysis
architecture development (high-level design)
design ( detailed design)
validation.
Q7. What are the fundamental concepts of object-oriented programming?
Object-oriented programming is an approach to solving problems(that is, designing and implementing programs) using objects to describe a real world problems and to build solutions to those problems. Collections of objects are abstracted to classes. A class is a collection of objects that have the same data and behave in the same way. Behavior results from the execution of methods or subroutines on the date values of an object. Classes are related by inheritance, which means that one class can inherit the data and methods of another class.
Q8. Name the four key concepts/features of object-oriented programming
Modularity
Abstraction
Composition
Hierarchy.
Q9. What are the ‘modules’ in oop called?
Objects, classes
Q11. How is composition done in object-oriented programming
Composition is done in object-oriented programming by the ineraction of objects via messages or calls to their methods.
질문 중 11번에서 composition은 어떻게 이루어지는지에 대해서 묻는데 그에 대한 대답이 이해가 안가서 찾아보고 정리합니다.
Composition in Java
1. has-a relationship between objects
2. Implemented using instance variables
3. Code reuse
4. Hide visibility to client classes
-Composition Example Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | package com.journaldev.composition; public class Job { private String role; private long salary; private int id; public String getRole() { return role; } public void setRole(String role) { this.role = role; } public long getSalary() { return salary; } public void setSalary(long salary) { this.salary = salary; } public int getId() { return id; } public void setId(int id) { this.id = id; } } package com.journaldev.composition; public class Person { //composition has-a relationship private Job job; public Person(){ this.job=new Job(); job.setSalary(1000L); } public long getSalary() { return job.getSalary(); } } | cs |
구성 요소와 샘플 코드를 보면 합성이 무엇인지 금방 알 수 있습니다. Person 클래스의 생성자에서 Job의 객체를 생성하고, 그 객체의 필드를 초기화합니다. 또, Job에 없는 메소드를 정의하여 사용합니다. 이때, 안에서 호출한 Job 클래스는 Person 클래스를 호출한 곳에서 보이지 않으며, Job 클래스의 코드를 재사용할 수 있습니다. 결론적으로 Person 객체와 Job 객체를 합친 합성 상태가 됩니다.
'MOOC > CS102 Introduction of CS2' 카테고리의 다른 글
Unit 5. Recursion 中 (0) | 2016.12.30 |
---|---|
Unit 3. Assessment Review (0) | 2016.12.30 |
Unit 3. C++ STL (0) | 2016.12.28 |
Unit 3. STL Main Design Idea (0) | 2016.12.28 |
Unit 2. The Building Blocks of Object-Oriented Programming (0) | 2016.12.10 |