Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
AnswerRe: Protecting "A Assembly"? Pin
Paul Conrad25-Nov-06 6:20
professionalPaul Conrad25-Nov-06 6:20 
GeneralRe: Protecting "A Assembly"? Pin
Ariston Darmayuda26-Nov-06 3:01
Ariston Darmayuda26-Nov-06 3:01 
GeneralRe: Protecting "A Assembly"? Pin
Amar Chaudhary26-Nov-06 14:07
Amar Chaudhary26-Nov-06 14:07 
AnswerRe: Protecting "A Assembly"? Pin
Scott Dorman27-Nov-06 4:58
professionalScott Dorman27-Nov-06 4:58 
QuestionSingleton interfaces, is that possible? Pin
User 665825-Nov-06 4:52
User 665825-Nov-06 4:52 
AnswerRe: Singleton interfaces, is that possible? Pin
S. Senthil Kumar25-Nov-06 6:29
S. Senthil Kumar25-Nov-06 6:29 
GeneralRe: Singleton interfaces, is that possible? Pin
User 665825-Nov-06 6:57
User 665825-Nov-06 6:57 
GeneralRe: Singleton interfaces, is that possible? [modified] Pin
S. Senthil Kumar25-Nov-06 7:23
S. Senthil Kumar25-Nov-06 7:23 
I cooked up a real quick example

using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    public interface IRenderer
    {
        void Render();
    }

    public abstract class Renderer : IRenderer
    {
        static IRenderer renderer;

        protected Renderer(){}

        public abstract void Render();

        public static IRenderer Instance
        {
            get
            {
                if (renderer == null)
                {
                    renderer = RendererFactory.CreateRenderer();
                }
                return renderer;
            }
        }
    }

    class RendererFactory
    {
        internal static IRenderer CreateRenderer()
        {
            return new ThreeDRenderer();
        }
    }

    public class ThreeDRenderer : Renderer
    {
        protected ThreeDRenderer(){}
        public override void Render() { Console.WriteLine("3DRenderer" + this.GetHashCode()); }
    }

    public class TwoDRenderer : Renderer
    {
        protected TwoDRenderer(){}
        public override void Render() { Console.WriteLine("2DRenderer" + this.GetHashCode()); }
    }

    public class ConsoleMain
    {
        public static void Main(string[] args)
        {
            Renderer.Instance.Render();
            Renderer.Instance.Render();
        }
    }
}


You could of course modify CreateRenderer to create different renderers based on parameters (like configuration information).

Does this help?

Regards
Senthil [MVP - Visual C#]
_____________________________
My Blog | My Articles | My Flickr | WinMacro

GeneralRe: Singleton interfaces, is that possible? Pin
User 665826-Nov-06 1:56
User 665826-Nov-06 1:56 
GeneralRe: Singleton interfaces, is that possible? Pin
S. Senthil Kumar26-Nov-06 5:44
S. Senthil Kumar26-Nov-06 5:44 
QuestionTo convert xml file to pdf file Pin
praveen pandey25-Nov-06 2:50
praveen pandey25-Nov-06 2:50 
QuestionDatabase connectivity problem Pin
ranandbe25-Nov-06 0:46
ranandbe25-Nov-06 0:46 
QuestionDraw Pin
MHASSANF25-Nov-06 0:40
MHASSANF25-Nov-06 0:40 
AnswerRe: Draw Pin
CPallini25-Nov-06 1:16
mveCPallini25-Nov-06 1:16 
Questionhow to insert my DatagridView1.Columns to another DatagridView? Pin
hdv21224-Nov-06 23:24
hdv21224-Nov-06 23:24 
AnswerRe: how to insert my DatagridView1.Columns to another DatagridView? Pin
Stathread25-Nov-06 7:19
Stathread25-Nov-06 7:19 
Questionany C# GUI samples/tutorials for .Net Compact Framework on WinCE Pin
George_George24-Nov-06 22:54
George_George24-Nov-06 22:54 
QuestionLimiting the retrived results using ODBC on MS access [modified] Pin
cbh_24-Nov-06 22:01
cbh_24-Nov-06 22:01 
AnswerRe: Limiting the retrived results using ODBC on MS access Pin
Eduard Keilholz26-Nov-06 20:36
Eduard Keilholz26-Nov-06 20:36 
QuestionPacking and unpacking bits Pin
ScruffyDuck24-Nov-06 21:31
ScruffyDuck24-Nov-06 21:31 
AnswerRe: Packing and unpacking bits Pin
Guffa24-Nov-06 23:16
Guffa24-Nov-06 23:16 
GeneralRe: Packing and unpacking bits Pin
ScruffyDuck24-Nov-06 23:33
ScruffyDuck24-Nov-06 23:33 
GeneralRe: Packing and unpacking bits Pin
CPallini25-Nov-06 0:07
mveCPallini25-Nov-06 0:07 
AnswerRe: Packing and unpacking bits Pin
Guffa25-Nov-06 0:34
Guffa25-Nov-06 0:34 
GeneralRe: Packing and unpacking bits Pin
ScruffyDuck25-Nov-06 1:08
ScruffyDuck25-Nov-06 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.