Skip to content

Commit 49d5ade

Browse files
committed
Interfaces just for reference in this repo ...
1 parent e70f7d9 commit 49d5ade

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

patterns/interfaces_une.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
// Interface
7+
class Decorator {
8+
public:
9+
Decorator(double angle) : angle(angle) {}
10+
virtual ~Decorator() {}
11+
virtual void whatever() = 0;
12+
protected:
13+
double angle;
14+
};
15+
16+
// Another Interface
17+
template<class T>
18+
class Complex {
19+
public:
20+
Complex(T *real, T *image)
21+
: real(real), image(image) {}
22+
~Complex() { delete real, image; }
23+
virtual void echoComplex() = 0;
24+
protected:
25+
T *real, *image;
26+
};
27+
28+
// IntComplex Implements both interfaces
29+
//
30+
class IntComplex : public Complex<int>, Decorator {
31+
public:
32+
IntComplex(int *real, int *image, int angle)
33+
: Complex<int>(real, image), Decorator(angle)
34+
{}
35+
void whatever() override {
36+
cout << "Decorating complex number with an angle of "
37+
<< Decorator::angle << endl;
38+
}
39+
void echoComplex() override {
40+
cout << " Y = " << *this->real << " + " << *this->image << "*J\n";
41+
}
42+
};
43+
44+
45+
int main() {
46+
47+
int *real = new int(3);
48+
int *image = new int(4);
49+
IntComplex *c1 = new IntComplex(real, image, 10);
50+
c1->whatever();
51+
c1->echoComplex();
52+
53+
delete real, image, c1;
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)