Sometimes you have many entities which have common parts, but also should be addressed uniquely in UI. For example, in a CMS, you have many content types (like news, images, articles, pages, etc.) which have title, URL, SEO settings, etc. in common, but which also have specific fields. For example, image have a path field, while news doesn't have that.
Now when you want to work with these items per page, you encounter long switch
and if
blocks. For example:
switch(currentLoadedContentType)
{
case ContentType.Gallery:
// Show gallery specific fields;
break;
case ContentType.News:
// Show news specific fields;
break;
case ContentType.Artiel:
// Show artiels specific fields;
break;
case ContentType.Page:
// Show pages specific fields;
break;
}
As you increase the number of content types, this lists gets longer and longer. What patterns are available to reduce the length or eliminate this long switch, but at the same time don't result in repetition. (I'm a big fan of DRY).