Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2016 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9c2003a79ed421587da5d0eb931f58c0 to your computer and use it in GitHub Desktop.
Save anonymous/9c2003a79ed421587da5d0eb931f58c0 to your computer and use it in GitHub Desktop.
/// I want to create tree like structures of "Elements"
/// Each Element has GeneralInformation (a name and a description)
/// There are two types of "Parent elements", e.g. elements that can have child elements:
/// * Links that have at most one dynamic child, two related properties and which can dynamically change their child with an update method
/// * Collections that have an arbitrary number of children, but don't provide an update method
/// Children can be any implementation of the base interface below, in particular elements, collections and links can all be children of collections and links
// Base interface
// Each element must have GeneralInformation
// Single responsibility principle enforces to put logic in GeneralInformation
// Law of Demeter enforces to proxy ElementName and ElementDescription in GeneralInformation
// This is also the base type for children, any implementation of any derived interface can be a child
public interface IElement
{
IGeneralInformation GeneralInformation { get; }
string ElementName { get; set; }
string ElementDescription { get; set; }
}
// Extended class type 1 - links can have exactly one child of arbitrary type
// We must inherit from IElement since we want to use ILink inmplementations as children
// Single responsibility principle enforces to put logic in LinkInformation
// Law of Demeter enforces to proxy ReferencedElement and UpdateLink in GeneralInformation
public interface ILink : IElement
{
ILinkInformation LinkInformation { get; }
IElement ReferencedElement { get; }
void UpdateLink(object arg);
}
// base functionality
public interface IGeneralInformation
{
string ElementName { get; set; }
string ElementDescription { get; set; }
}
// extended functionality type 1
public interface ILinkInformation
{
bool IsTargetRelative { get; set; }
bool IsTargetGlobal { get; set; }
IElement ReferencedElement { get; }
void UpdateLink(object arg);
}
// extended functionality type 2
public interface ICollectionInformation
{
IList<IElement> listOfChildren { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment