Factory Method, Abstract Factory, Prototype, Singleton, Builder, Adapter, Bridge, Decorator - #32
Open
armine-v wants to merge 11 commits into
Open
Factory Method, Abstract Factory, Prototype, Singleton, Builder, Adapter, Bridge, Decorator#32armine-v wants to merge 11 commits into
armine-v wants to merge 11 commits into
Conversation
added 7 commits
March 2, 2021 00:32
hrachtandilyan
requested changes
Mar 10, 2021
| } | ||
| }; | ||
|
|
||
| enum ArmorPiece { HEADGEAR, BOOTS, CUIRASS, GAUNTLETS }; |
| enum ArmorPiece { HEADGEAR, BOOTS, CUIRASS, GAUNTLETS }; | ||
|
|
||
| class Equipment { | ||
| private: map<ArmorPiece,Armor*> _equipment; |
Owner
There was a problem hiding this comment.
Replace this map by simple Armor piece fields (one for each type, e.g. one Headgear).
Comment on lines
+134
to
+145
| virtual Gauntlets* MakeGauntlets() const | ||
| { cout<<"Standard gauntlets forged."<<endl; | ||
| return new Gauntlets; } | ||
| virtual Headgear* MakeHeadgear() const | ||
| { cout<<"Standard headgear forged."<<endl; | ||
| return new Headgear; } | ||
| virtual Cuirass* MakeCuirass() const | ||
| { cout<<"Standard cuirass forged."<<endl; | ||
| return new Cuirass; } | ||
| virtual Boots* MakeBoots() const | ||
| { cout<<"Standard boots forged."<<endl; | ||
| return new Boots; } |
Owner
There was a problem hiding this comment.
Please fix the indentation.
| class Equipment { | ||
| private: map<ArmorPiece,Armor*> _equipment; | ||
| public: | ||
| void AddGauntlets(Gauntlets* g) |
Owner
There was a problem hiding this comment.
All the add methods should become set methods.
Comment on lines
+37
to
+64
| /* | ||
| //Factory method using templates | ||
| //We'll be using the base class and its subclasses defined above | ||
| //Using templates, we won't have to create a subclass factory for each product type | ||
|
|
||
| class ArmorFactory { | ||
| public: | ||
| virtual Armor* CreateArmor() = 0; | ||
| }; | ||
|
|
||
| template <class ArmorType> | ||
| class ArmorCreator: public ArmorFactory { | ||
| public: | ||
| virtual Armor* CreateArmor(); | ||
| }; | ||
|
|
||
| template <class ArmorType> | ||
| Armor* ArmorCreator<ArmorType>::CreateArmor() | ||
| { | ||
| cout<<typeid(ArmorType).name()<<" forged\n"; | ||
| return new ArmorType; | ||
| } | ||
| */ | ||
|
|
||
| /* | ||
| If we use templates, all the factory classes | ||
| defined below will have to be deleted | ||
| */ |
Owner
There was a problem hiding this comment.
If not used, better be deleted.
Comment on lines
+114
to
+128
| /* | ||
| //Factory method using templates | ||
|
|
||
| ArmorCreator<Armor> standardArmorFactory; | ||
| standardArmorFactory.CreateArmor(); | ||
|
|
||
| ArmorCreator<DragonboneArmor> dragonboneArmorFactory; | ||
| dragonboneArmorFactory.CreateArmor(); | ||
|
|
||
| ArmorCreator<ElvenArmor> elvenArmorFactory; | ||
| elvenArmorFactory.CreateArmor(); | ||
|
|
||
| ArmorCreator<DaedricArmor> daedricArmorFactory; | ||
| daedricArmorFactory.CreateArmor(); | ||
| */ |
Owner
There was a problem hiding this comment.
You can separately have a factory method example using those template implementations.
…d AbstractFactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.