Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Cinema {
- public interface ICinema {
- }
- public sealed class CinemaFactory {
- // Singleton pattern to support extension methods. (Can't add extension methods to static classes.)
- private static readonly Lazy<CinemaFactory> LazyInstance = new Lazy<CinemaFactory> (() => new CinemaFactory());
- public static CinemaFactory Instance {
- get {
- return LazyInstance.Value;
- }
- }
- private CinemaFactory () {
- }
- public ICinema GetCinema (EndpointAddress10 RemoteCinemaUri) {
- ICinema CinemaEngineInstance;
- // Get a reference from the WCF service...
- return CinemaEngineInstance;
- }
- }
- }
- namespace Cinema.Engine {
- using Cinema;
- public class CinemaEngine : ICinema {
- }
- // Add polymorphism to the class defined in a different project.
- public static class CinemaFactoryHelper {
- public static ICinema GetCinema (this CinemaFactory _This) {
- return new CinemaEngine ();
- }
- }
- }
- namespace Cinema.Client1 {
- using Cinema;
- public class Consumer1 {
- // Intellisense shows that there are no overloads to the GetCinema() method. Yay!
- private ICinema ref = CinemaFactory.Instance.GetCinema (EndpointAddress10.FromEndpointAddress (new EndpointAddress ("http://localhost"));
- }
- }
- namespace Cinema.Client2 {
- using Cinema;
- using Cinema.Engine; // Add visibility to the extension method that provides a local instance of the engine.
- public class Consumer2 {
- // Intellisense shows the method +1 overload. Yay!
- private ICinema ref = CinemaFactory.Instance.GetCinema ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement