쫑가 과정

객체 지향 프로그래밍의 추상화 본문

Unity/이론

객체 지향 프로그래밍의 추상화

쫑가 2021. 12. 27. 19:02

https://learn.unity.com/tutorial/abstraction-in-object-oriented-programming?uv=2020.3&pathwayId=5f7e17e1edbc2a5ec21a20af&missionId=5f779f1eedbc2a00201f3e5e# 

 

Abstraction in object-oriented programming - Unity Learn

In this tutorial, you’ll learn about the first pillar of object-oriented programming: Abstraction. By the end of this tutorial, you will be able to: Explain how abstraction is used to expose only necessary script components Expose only the important deta

learn.unity.com

Abstraction in object-oriented programming

 
객체 지향 프로그래밍의 첫 번째 기둥인 추상화
추상화 목표
 
1. 추상화를 사용해 필요한 스크립트 구성 요소만 노출하는 방법
2. 추상화를 구현할 기회를 정확하게 인식해 객체의 중요한 세부 사항만 노출
 
외부 기능을 변경하지 않고 유지하면서 소프트웨어의 디자인, 구조 및 구현을 개선한다.
 
코드 리팩토링(Code Refactoring)이라고 부른다.
 

Code refactoring - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Restructuring existing computer code without changing its external behavior This article is about a behaviour-preserving change. It is not to be confused with Rewrite (programming). In

en.wikipedia.org

다른 프로그래머가 볼 수 있는 스크립트에서 복잡한 코드를 제거하고 다른 프로그래머가 실제로 필요로 하는 기능만 노출한다.

코드 리팩토링의 중요한 부분

다른 프로그래머가 코드와 상호 작용하는 방식을 변경하지 않고 기능을 개선하는 것.

 

예) 반복해서 사용하는 기능을 메서드화 하기.

private void Start()
{
    for (int i = 0; i < 3; i++)
    {
        Instantiate(enemyPrefab, GenerateSpawnPosition(),   
        enemyPrefab.transform.rotation);
    }
}

=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>

void SpawnEnemyWave() // create new higher-level method 
{
    for (int i = 0; i < 3; i++)
    {
        Instantiate(enemyPrefab, GenerateSpawnPosition(), 
        enemyPrefab.transform.rotation);
    }
}

private void Start()
{
    SpawnEnemyWave(); // call higher-level method in Start()
}

메서드를 호출만 하면 기능이 작동하기에 메서드 호출을 변경하지 않는 한, 메서드 내용을 안전하게 조정할 수 있다.

 

자신의 응용 프로그램에 추상화를 적용하거나 시도할 수 있는 방법에 대해 생각해보자.

 

Comments