Recently I am going through the source code of a graphics engine, but got stuck with a pattern that I can't identify what it is.
// AbstractComponent.h
class AbstractComponent
{
friend class Node;
private:
std::shared_ptr<Node> _node;
};
// Node.h
class Node
{
private:
std::list<std::shared_ptr<AbstractComponent>> _components;
public:
std::shared_ptr<Node> addComponent(std::shared_ptr<AbstractComponent> component);
std::shared_ptr<Node> removeComponent(std::shared_ptr<AbstractComponent> component);
protected:
Node();
};
I am guessing this is the composite pattern but I cannot confirm it is. And if it really is, what is the advantage of using friend class instead of the conventional composite pattern I can find online? (for example like this one: http://ift.tt/2sihheB)
Aucun commentaire:
Enregistrer un commentaire