//Define the IComponent interface to be used as the "blueprint" for the composite and component classes.
public interface IComponent
{
bool Add(IComponent component);
bool Remove(IComponent component);
IComponent Find(string name);
string Display();
string Name { get; set; }
}

//The Album class (object) inherits from the IComponent interface and represents the composite component.
//This class contains a list of IComponent components.
public class Album : IComponent
{
public string Name { get; set; }
public List<IComponent> Photos { get; private set; }

public Album(string name)
{
Name = name;
Photos = new List<IComponent>();
}

public bool Add(IComponent component)
{
Photos.Add(component);
return (true);
}

public bool Remove(IComponent component)
{
IComponent componentFound = Find(component.Name);

if (componentFound != null)
{
Photos.Remove(componentFound);
return (true);
}

return (false);
}

public IComponent Find(string name)
{
return Photos.Find(delegate(IComponent component)
{
return (component.Name == name);
}
);
}

public string Display()
{
StringBuilder sb = new StringBuilder();
foreach (IComponent component in Photos)
{
sb.Append(string.Format("Photo: {0}\n", component.Name));
}

return (sb.ToString());
}
}

//The Photo class (object) inherits from the IComponent interface and represents a single component.
public class Photo : IComponent
{
public string Name { get; set; }

public Photo(string name)
{
Name = name;
}

public bool Add(IComponent component)
{
throw new Exception("Cannot add to a Photo.");
}

public bool Remove(IComponent component)
{
throw new Exception("Cannot remove Photo directly.");
}

public bool Find(string name)
{
throw new Exception("Cannot find a Photo.");
}

public string Display()
{
return (string.Format("The name of the photo is {0}.", Name));
}

public override string ToString()
{
return Name;
}
}