www.schackmann.net deutsch english

design pattern

  • singleton
    Es wird zur Laufzeit nur eine Instanz dieser Klasse erzeugt.

    using System;
    
    namespace Core
    {
    	/// <summary>
    	/// The factory.
    	/// Its purpose is to create the required checking object for the actual dataset.
    	/// </summary>
    	public class ASingleton
    	{
    
    		private static ASingleton self;
    
    		/// <summary>
    		/// Constructor.
    		/// </summary>
    		private ASingleton()
    		{
    		}
    
    		/// <summary>
    		/// This function returns the only instance and creates it if required.
    		/// </summary>
    		/// <returns>the instance.</returns>
    		public static volatile ASingleton GetInstance()
    		{
    			/// Test if there is an instance
    			if( self == null )
    				lock( typeof( this ))
    					self = new ASingleton();
    
    			return self;
    		}
    
    	}
    }
    
  • factory
    Abhängig vom Parameter wird ein abgeleitetes Objekt zurückgegeben.
    using System;
    
    namespace Core
    {
    	/// <summary>
    	/// The factory.
    	/// Its purpose is to create the required checking object for the actual dataset.
    	/// </summary>
    	public class ACheckFactory
    	{
    
    		/// <summary>
    		/// Constructor.
    		/// </summary>
    		public ACheckFactory()
    		{
    		}
    
    		/// <summary>
    		/// This function creates and returns the required checker object.
    		/// </summary>
    		/// <param name="ds">the dataset to be checked.</param>
    		/// <returns>the checker that will do the job.</returns>
    		public ACheckBase GetChecker(AODataSet ds)
    		{
    			/// Test if Dataset is Intern or Extern 
    			/// it will create different derivates of ACheckBase
    			if( ds.isExtern )
    				return new ACheckExtern(ds);
    			else
    				return new ACheckIntern(ds);
    		}
    
    	}
    }
    
  • adapter
    Interfaceanpassung