상세 컨텐츠

본문 제목

Python 객체지향 스타일로 로직 작성하기

Python

by techbard 2016. 5. 6. 09:46

본문

반응형

# 두 개 리스트를 가진 인스턴스를 생성해서 BO, Data, UI 구조의 객체지향 프로그래밍


class Data():

def __init__(self, this_list):

self.my_list = this_list


def get_data(self):

return self.my_list


class Calc():

def __init__(self, one, two):

self.one = one

self.two = two


def get_calc_list(self):

new_list = [x + y for x, y in zip(self.one.get_data(), self.two.get_data())]

return Data(new_list).get_data()


class UI():

def __init__(self):

self.one = Data([1, 1])

self.two = Data([1, 2])


def get_calc(self):

c = Calc(self.one, self.two)

return c.get_calc_list()


u = UI()

print(u.get_calc())


# 결과

[2, 3]


반응형

관련글 더보기

댓글 영역