mirror of
https://github.com/JakubVojvoda/design-patterns-cpp.git
synced 2025-12-16 20:37:05 +03:00
add Abstract Factory
This commit is contained in:
28
README.md
28
README.md
@@ -3,18 +3,17 @@
|
||||
Software design patterns are general reusable solutions to problems which occur
|
||||
over and over again in object-oriented design enviroment. It is not a finished
|
||||
design that can be transformed into source code directly, but it is template how
|
||||
to solve the problem. Templates in this repository are based mainly on book
|
||||
[Design Patterns by The "Gang of Four"]. We can classify them by purpose
|
||||
into creational (abstract the instantiation process), structure (how classes and
|
||||
objects are composed to form larger structures) and behavioral patterns (the
|
||||
assignment of responsibilities between objects).
|
||||
to solve the problem. We can classify them by purpose into creational (abstract
|
||||
the instantiation process), structure (how classes and objects are composed to form
|
||||
larger structures) and behavioral patterns (the assignment of responsibilities between
|
||||
objects).
|
||||
|
||||
- Creational Patterns
|
||||
- [Abstract Factory], families of product objects
|
||||
- [Builder], todo
|
||||
- [Factory Method], todo
|
||||
- [Prototype], todo
|
||||
- [Singleton], todo
|
||||
- [Builder], how a composite object gets created
|
||||
- [Factory Method], subclass of object that is instantiated
|
||||
- [Prototype], class of object that is instantiated
|
||||
- [Singleton], the sole instance of a class
|
||||
- Structural Patterns
|
||||
- [Adapter], todo
|
||||
- [Bridge], todo
|
||||
@@ -43,10 +42,21 @@ In my repository you can find implementation of desgin patterns also in language
|
||||
* [Design Patterns in Java]
|
||||
* [Design Patterns in Python]
|
||||
|
||||
### References
|
||||
Design patterns in this repository are based on
|
||||
|
||||
* [Design Patterns by The "Gang of Four"]
|
||||
* [Head First: Design Patterns]
|
||||
* [Wikipedia]
|
||||
|
||||
[Design Patterns in C++]: https://github.com/JakubVojvoda/design-patterns-cpp
|
||||
[Design Patterns in Java]: https://github.com/JakubVojvoda/design-patterns-java
|
||||
[Design Patterns in Python]: https://github.com/JakubVojvoda/design-patterns-python
|
||||
|
||||
[Design Patterns by The "Gang of Four"]: https://en.wikipedia.org/wiki/Design_Patterns
|
||||
[Head First: Design Patterns]: http://www.headfirstlabs.com/books/hfdp/
|
||||
[Wikipedia]: https://en.wikipedia.org/wiki/Software_design_pattern
|
||||
|
||||
[Abstract Factory]: https://github.com/JakubVojvoda/design-patterns-cpp/tree/master/abstract-factory
|
||||
[Builder]: https://github.com/JakubVojvoda/design-patterns-cpp/tree/master/builder
|
||||
[Factory Method]: https://github.com/JakubVojvoda/design-patterns-cpp/tree/master/factory-method
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Author: Jakub Vojvoda [github.com/JakubVojvoda]
|
||||
* 2016
|
||||
*
|
||||
* Source code is licenced under MIT licence
|
||||
* Source code is licensed under MIT licence
|
||||
* (for more details see LICENCE)
|
||||
*
|
||||
*/
|
||||
@@ -28,14 +28,14 @@ public:
|
||||
class ConcreteProductAX : public ProductA {
|
||||
public:
|
||||
std::string getName() {
|
||||
return "A - X";
|
||||
return "A-X";
|
||||
}
|
||||
// ...
|
||||
};
|
||||
|
||||
class ConcreteProductAY : public ProductA {
|
||||
std::string getName() {
|
||||
return "A - Y";
|
||||
return "A-Y";
|
||||
}
|
||||
// ...
|
||||
};
|
||||
@@ -57,14 +57,14 @@ public:
|
||||
*/
|
||||
class ConcreteProductBX : public ProductB {
|
||||
std::string getName() {
|
||||
return "B - X";
|
||||
return "B-X";
|
||||
}
|
||||
// ...
|
||||
};
|
||||
|
||||
class ConcreteProductBY : public ProductB {
|
||||
std::string getName() {
|
||||
return "B - Y";
|
||||
return "B-Y";
|
||||
}
|
||||
// ...
|
||||
};
|
||||
@@ -117,5 +117,6 @@ int main()
|
||||
|
||||
ProductA *p2 = factoryY->createProductA();
|
||||
std::cout << "Product: " << p2->getName() << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
## Abstract Factory
|
||||
|
||||
Abstract factory pattern has creational purpose and provides an interface for creating families of related or dependent objects without specifying their concrete classes.
|
||||
Pattern applies to classes where deals with relationships through inheritence ie. they are static-fixed at compile time.
|
||||
Abstract factory pattern has creational purpose and provides an interface for
|
||||
creating families of related or dependent objects without specifying their
|
||||
concrete classes. Pattern applies to object and deal with object relationships,
|
||||
which are more dynamic. In contrast to Factory Method, Abstract Factory pattern
|
||||
produces family of types that are related, ie. it has more than one method of
|
||||
types it produces.
|
||||
|
||||
|
||||
### When to use
|
||||
|
||||
* a system should be independent of how its products are created, composed, and represented
|
||||
* a system should be configured with one of multiple families of products
|
||||
* a family of related product objects is designed to be used together
|
||||
* you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
|
||||
Reference in New Issue
Block a user