일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- elk stack
- C언어
- nvidia docker
- 도커
- docker
- 자바
- 백준
- MySQL
- c++
- java
- 파이썬
- 데이트
- 스트림셋
- 클라우드
- mysql docker
- 도커 elk
- 코딩
- mysql on docker
- 도커 시작하기
- 정보처리기사
- 알고리즘
- 도커 mysql
- 스트림셋이란?
- 데이터베이스
- streamsets 강의
- python
- 앤서블 설치
- c
- 푸시푸시
- ansible install
- Today
- Total
리그캣의 개발놀이터
소프트웨어 설계 - Abstract class 예제 본문
Abstract class
추상클래스 확장성이 뛰어나다. figure가 가지고 있는 공통 특징을 물려줄수 있다. 기본을 가지고 확장.
Abstract Operation
implemention
ex
// figure.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다. // #include "stdafx.h" #include <iostream> using namespace std; class Figure { int color; public: void setColor(int c) { color = c; } virtual void move(int dx, int dy) = 0; //abstract op virtual void draw() = 0; Figure(int c) { color = c; cout << "Figure::Figure(int)" << endl; } virtual ~Figure() { cout << "Figure::~Figure()\n "; } }; class Point { int x, y; public: void move(int dx, int dy) { x += dx; y += dy; cout << "Point::move(int,int)\n"; } Point(int xp, int yp) { x = xp; y = yp; cout << "Point::Point(int, int)\n"; } ~Point() { cout << "Point::~Point()\n"; } }; class Circle : public Figure { Point center; int radius; public: void move(int dx, int dy) { center.move(dx, dy); cout << "Circle::move(int,int)\n"; } void draw() { cout << "Circle::draw()\n"; } void setRadius(int r) { radius = r; } Circle(int x, int y, int r, int c) : Figure(c), center(x, y) { radius = r; cout << "Circle::Circle(int,int,int,int)\n"; } ~Circle() { cout << "Circle::~Circle()\n"; } }; class Rectangle : public Figure { Point topleft; int width, height; public: void move(int dx, int dy) { topleft.move(dx, dy); cout << "Rectangle::move(int,int)\n"; } void draw() { cout << "Rectangle::draw()\n"; } void setWidth(int w) { width = w;} void setHeight(int h) { height = h; } Rectangle(int x, int y, int w, int h, int c) : Figure(c), topleft(x, y) { width = w; height = h; cout << "Rectangle::Rectangle(int,int,int,int,int)\n"; } ~Rectangle() { cout << "Rectangle::~Rectangle()\n"; } }; int main() { Figure *f[10]; int num = 4; f[0] = new Circle(100, 100, 50, 2); f[1] = new Circle(200, 200, 30, 2); f[2] = new Rectangle(10, 10, 50, 40, 3); f[3] = new Rectangle(100, 100, 70, 30, 4); int dx = 10, dy = 20, i; for (i = 0; i < num; i++) f[i]->move(dx, dy); for (i = 0; i < num; i++) f[i]->draw(); for (i = 0; i < num; i++) delete f[i]; return 0; } |
'프로그래밍 기본 > 소프트웨어 설계' 카테고리의 다른 글
소프트웨어 설계 - UML 소개 (0) | 2018.01.25 |
---|---|
소프트웨어 설계 - 캡슐화 상속 (0) | 2018.01.25 |
소프트웨어 설계 - 설계 단계 (0) | 2018.01.25 |
소프트웨어 설계 - star uml 사용법 (0) | 2018.01.25 |
소프트웨어 설계 - 응집도와 결합도 (0) | 2018.01.25 |