Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What kind of items expected by list in below case? Please see the code.
Am learning design patterns, i have one doubt here. See below code
XML
abstract class Element
{

    public abstract void Accept(Visitor visitor);

}



/// <summary>

/// A 'ConcreteElement' class

/// </summary>

class ConcreteElementA : Element
{

    public override void Accept(Visitor visitor)
    {

        visitor.VisitConcreteElementA(this);

    }



    public void OperationA()
    {

    }

}



/// <summary>

/// A 'ConcreteElement' class

/// </summary>

class ConcreteElementB : Element
{

    public override void Accept(Visitor visitor)
    {

        visitor.VisitConcreteElementB(this);

    }



    public void OperationB()
    {

    }

}



/// <summary>

/// The 'ObjectStructure' class

/// </summary>

class ObjectStructure
{

    private List<Element> _elements = new List<Element>();



    public void Attach(Element element)
    {

        _elements.Add(element);

    }



    public void Detach(Element element)
    {

        _elements.Remove(element);

    }




here What kind of items expected by list List<<element>> _elements. Ie if it is like List<<int>>means it is expecting integer values. So we can add integer values to that list. But i dont understand in my case what is happening? What kind of items are adding to that list element ?

See full code in below link,

C#
http://www.dofactory.com/net/visitor-design-pattern
[^]
Posted
Updated 15-Feb-15 20:26pm
v2
Comments
Sinisa Hajnal 16-Feb-15 2:31am    
You can add ConcreteElementA and ConcreteElementB classes and any other class that inherits from Element. This is valid because ConcreteElementA IS an element.
Am Gayathri 16-Feb-15 2:34am    
Thank u so much for quick and clear replay..If you give this as answer i would have clicked 'Accept Answer'. :)

1 solution

You can add ConcreteElementA and ConcreteElementB classes and any other class that inherits from Element. This is valid because ConcreteElementA IS an element.

There you go :)

Next time when you're adding tags, please decide on one version, you don't have to list everything that has C# in the text.

Thank you.
 
Share this answer
 
Comments
Am Gayathri 16-Feb-15 7:19am    
Ok Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900