code refactoring: fix memory leaks, code style, etc.

This commit is contained in:
Jakub Vojvoda
2019-01-31 19:57:40 +01:00
parent a8681552c4
commit a0b0ea4f8e
24 changed files with 960 additions and 566 deletions

View File

@@ -14,8 +14,11 @@
* Target
* defines specific interface that Client uses
*/
class Target {
class Target
{
public:
virtual ~Target() {}
virtual void request() = 0;
// ...
};
@@ -25,11 +28,14 @@ public:
* all requests get delegated to the Adaptee which defines
* an existing interface that needs adapting
*/
class Adaptee {
class Adaptee
{
public:
void specificRequest() {
~Adaptee() {}
void specificRequest()
{
std::cout << "specific request" << std::endl;
// ...
}
// ...
};
@@ -40,11 +46,12 @@ public:
* to request on a Target by extending both classes
* ie adapts the interface of Adaptee to the Target interface
*/
class Adapter : public Target, private Adaptee {
class Adapter : public Target, private Adaptee
{
public:
virtual void request() {
virtual void request()
{
specificRequest();
// ...
}
// ...
};
@@ -54,6 +61,7 @@ int main()
{
Target *t = new Adapter();
t->request();
delete t;
return 0;
}

View File

@@ -14,8 +14,11 @@
* Target
* defines specific interface that Client uses
*/
class Target {
class Target
{
public:
virtual ~Target() {}
virtual void request() = 0;
// ...
};
@@ -26,11 +29,12 @@ public:
* to Adapter it will get calls that client makes on the Target
*
*/
class Adaptee {
class Adaptee
{
public:
void specificRequest() {
void specificRequest()
{
std::cout << "specific request" << std::endl;
// ...
}
// ...
};
@@ -40,17 +44,20 @@ public:
* implements the Target interface and when it gets a method call it
* delegates the call to a Adaptee
*/
class Adapter : public Target {
class Adapter : public Target
{
public:
Adapter() : adaptee() {}
~Adapter() {
~Adapter()
{
delete adaptee;
}
void request() {
void request()
{
adaptee->specificRequest();
// ...
// ...
}
// ...
@@ -64,6 +71,7 @@ int main()
{
Target *t = new Adapter();
t->request();
delete t;
return 0;
}