이모저모

절차/객체/관점 지향 프로그래밍 본문

coding/Java, Spring

절차/객체/관점 지향 프로그래밍

Jeo 2022. 2. 21. 10:47

절차 지향 프로그래밍(Procedural Programming)

순차적 처리를 중요시하는 프로그래밍 기법 

        // 사람들이 있었다.
        int grandfather = 95;
        int father = 62;
        int mother = 64;

        // 5살만큼 나이가 들었다.
        int new_grandfather = grandfather + 5;
        int new_father = father + 5;
        int new_mother = mother + 5;

컴퓨터의 처리구조와 유사하여 속도가 빠름

하지만 모든 구성요소가 유기적으로 연결되어 있어 문제가 생겼을 때 부분적 해결이 어려움 (디버깅, 유지보수가 어려움)

- 대표적 언어: C언어, COBOL 등

 

객체 지향 프로그래밍 (Object Oriented Programming) 

프로그래밍에 필요한 속성(attribute)과 메서드(method)를 가진 클래스(class)를 정의하고, 정의된 클래스를 통해 객체를 생성하여 객체들 간 관계, 상호작용을 통해 로직을 구성하는 프로그래밍 기법

class Person {
    // 모든 사람이 갖는 공통 속성(나이)
    private final int age;

    public Person(int age) {
        this.age = age;
    }

    // 모든 사람이 갖는 공통 메소드(나이먹기)
    public int getAge(int n) {
        return age + n;
    }
}


public class Sample {
    public static void main(String[] args) {

        Person grandpa = new Person(95);
        Person father = new Person(62);
        Person mother = new Person(64);

        grandpa.getAge(5);
        father.getAge(5);
        mother.getAge(5);
    }
}

- 대표적 언어: JAVA, C++, 파이썬

 

관점 지향 프로그래밍(Aspect Oriented Programming)

핵심기능을 중심으로 묶인 각각의 객체들이 공통적인 로직을 가질 때, 이러한 기능을 횡적으로 잡아내는 것

객체 지향 프로그래밍을 더욱 발전시키기 위한 개념

 

핵심 관심(core concern) : 각 서비스의 핵심 비즈니스 로직

횡단 관심(crosscut concern) : 로깅, 보안, 트랜젝션 등 공통 모듈화 할 수 있는 것

 

 

Comments