Adaptation
Category: Infrastructure
—
Other products by this author
Current release: Adaptation 1.0.0
Released 2007-07-01 — tested with .NET 2.0
Production 1.0.0 release of Adaptation. This release is feature-complete.
Experimental releases
Upcoming and alpha/beta/candidate releases
- Alpha releases should only be used for testing and development.
- Beta releases and Release Candidates are normally released for production testing, but should not be used on mission-critical sites.
- Always install on a separate test server first, and make sure you have proper backups before installing.
Release roadmap for Adaptation…
Project Description
- Project resources
The adapter pattern is used to 'adapt' an interface provided by a class to one that a consuming pattern can use.
This software implements a registry where adapters can be registered to provide an interface given one or more context objects.
This allows smaller, simpler components.
Typical usage might be as follows:
// Register our adapters
registry.Register(typeof(IEvent), typeof(IHTMLDisplay), typeof(EventHtmlAdapter));
registry.Register(typeof(IImage), typeof(IHTMLDisplay), typeof(ImageHtmlAdapter));
registry.Register(typeof(INewsItem), typeof(IHTMLDisplay), typeof(NewsHtmlAdapter));
// Create our basic objects
// implements IEvent
Event ev = new Event();
// implements INewsItem
NewsItem news = new NewsItem();
// Implements IImage
Image im = new Image();
// Use a SimpleLookup for basic lookup policies
SimpleLookup lookup = new SimpleLookup(registry);
IHTMLDisplay adapter;
foreach(object ob in new object[] { ev, news, im })
{
adapter = lookup.AdaptTo<IHTMLDisplay>(ob);
System.Console.WriteLine(adapter.HTML);
}
// Actually, you can register and lookup by class too,
// not just interface
registry = new Registry();
registry.Register(typeof(Event), typeof(IHTMLDisplay), typeof(EventHtmlAdapter));
registry.Register(typeof(Image), typeof(IHTMLDisplay), typeof(ImageHtmlAdapter));
registry.Register(typeof(NewsItem), typeof(IHTMLDisplay), typeof(NewsHtmlAdapter));
lookup = new SimpleLookup(registry);
// This prints the same output as last time
foreach(object ob in new object[] { ev, news, im })
{
adapter = lookup.AdaptTo<IHTMLDisplay>(ob);
System.Console.WriteLine(adapter.HTML);
}
Self-Certification
[ ] Internationalized
[X] Unit tests
[ ] End-user documentation
[ ] Internal documentation (documentation, interfaces, etc.)
[ ] Existed and maintained for at least 6 months
[ ] Installs and uninstalls cleanly
[ ] Code structure follows best practice
Independent Review