Skip to content

Factory Method, Abstract Factory, Prototype, Singleton, Builder, Adapter, Bridge, Decorator - #32

Open
armine-v wants to merge 11 commits into
hrachtandilyan:masterfrom
armine-v:master
Open

Factory Method, Abstract Factory, Prototype, Singleton, Builder, Adapter, Bridge, Decorator#32
armine-v wants to merge 11 commits into
hrachtandilyan:masterfrom
armine-v:master

Conversation

@armine-v

@armine-v armine-v commented Mar 2, 2021

Copy link
Copy Markdown

No description provided.

@armine-v armine-v changed the title DP: Factory Method Implementation (Homework 1) Factory Method & Abstract Factory Mar 8, 2021
}
};

enum ArmorPiece { HEADGEAR, BOOTS, CUIRASS, GAUNTLETS };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

enum ArmorPiece { HEADGEAR, BOOTS, CUIRASS, GAUNTLETS };

class Equipment {
private: map<ArmorPiece,Armor*> _equipment;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation.

class Equipment {
private: map<ArmorPiece,Armor*> _equipment;
public:
void AddGauntlets(Gauntlets* g)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
*/

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can separately have a factory method example using those template implementations.

@armine-v armine-v changed the title Factory Method & Abstract Factory Factory Method, Abstract Factory, Prototype Mar 16, 2021
@armine-v armine-v changed the title Factory Method, Abstract Factory, Prototype Factory Method, Abstract Factory, Prototype, Singleton, Builder Apr 13, 2021
@armine-v armine-v changed the title Factory Method, Abstract Factory, Prototype, Singleton, Builder Factory Method, Abstract Factory, Prototype, Singleton, Builder, Adapter, Bridge, Decorator Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants