Click here to Skip to main content
15,889,096 members
Home / Discussions / C#
   

C#

 
AnswerRe: Binding combo-box to Entity Data Model Pin
RobCroll6-Mar-12 10:48
RobCroll6-Mar-12 10:48 
GeneralRe: Binding combo-box to Entity Data Model Pin
pmcm6-Mar-12 22:37
pmcm6-Mar-12 22:37 
QuestionGetting information about a process's handles. Pin
Septimus Hedgehog6-Mar-12 2:09
Septimus Hedgehog6-Mar-12 2:09 
AnswerRe: Getting information about a process's handles. Pin
Eddy Vluggen6-Mar-12 5:20
professionalEddy Vluggen6-Mar-12 5:20 
AnswerRe: Getting information about a process's handles. Pin
Dave Kreskowiak6-Mar-12 5:35
mveDave Kreskowiak6-Mar-12 5:35 
GeneralRe: Getting information about a process's handles. Pin
Septimus Hedgehog6-Mar-12 6:50
Septimus Hedgehog6-Mar-12 6:50 
GeneralRe: Getting information about a process's handles. Pin
Septimus Hedgehog6-Mar-12 23:51
Septimus Hedgehog6-Mar-12 23:51 
QuestionHow do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 0:07
GParkings6-Mar-12 0:07 
Hi all,

I am a fan of factory and interface driven development but often find myself working amongst people i do not trust to stick to such patterns. As a result i have taken to using a couple of techniques to ensure instantiation happens via factories:

1. Private nested concrete implementations

In this approach i have the default concrete implementation of an interface decalred as private nested classes within the factory an exposed as interfaces

C#
public interface IFoo{};

private static class FooFactory
{

    public static IFoo CreateFoo()
    {
        return new Foo();
    }

    private class Foo : IFoo
    {
         public Foo(){};     
    }

}


2. Protected constructors with nested subclass

I came up with this approach as i needed to work with concrete classes (due to quirks of operator overloads) but still did'nt want the classes instantiated outside of the factory. The concrete class is publicly available but has a protected constructor. within the factory is a subclass of the concrete class that makes the constructor available to the factory

C#
public class Foo
{
    protected Foo(){};
}

public static class FooFactory
{
    public static Foo CreateFoo()
    {
        return new FooProvider();
    }

    private class FooProvider : Foo
    {
        public FooProvider(){}
    }
}


What techniques do everyone use to enforce use of a singleton factory? or do you simply trust your fellow developers to do things properly?
Pedis ex oris
Quidquid latine dictum sit, altum sonatur

AnswerRe: How do you enforce use of dedicated factories? Pin
BobJanova6-Mar-12 0:40
BobJanova6-Mar-12 0:40 
GeneralRe: How do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 1:01
GParkings6-Mar-12 1:01 
GeneralRe: How do you enforce use of dedicated factories? Pin
BobJanova6-Mar-12 1:58
BobJanova6-Mar-12 1:58 
GeneralRe: How do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 2:30
GParkings6-Mar-12 2:30 
GeneralRe: How do you enforce use of dedicated factories? Pin
jschell6-Mar-12 8:54
jschell6-Mar-12 8:54 
AnswerRe: How do you enforce use of dedicated factories? Pin
Eddy Vluggen6-Mar-12 0:46
professionalEddy Vluggen6-Mar-12 0:46 
GeneralRe: How do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 1:03
GParkings6-Mar-12 1:03 
AnswerRe: How do you enforce use of dedicated factories? Pin
Eddy Vluggen6-Mar-12 5:19
professionalEddy Vluggen6-Mar-12 5:19 
GeneralRe: How do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 5:51
GParkings6-Mar-12 5:51 
GeneralRe: How do you enforce use of dedicated factories? Pin
Eddy Vluggen6-Mar-12 6:55
professionalEddy Vluggen6-Mar-12 6:55 
AnswerRe: How do you enforce use of dedicated factories? Pin
PIEBALDconsult6-Mar-12 2:28
mvePIEBALDconsult6-Mar-12 2:28 
AnswerRe: How do you enforce use of dedicated factories? Pin
SledgeHammer016-Mar-12 6:30
SledgeHammer016-Mar-12 6:30 
GeneralRe: How do you enforce use of dedicated factories? Pin
GParkings6-Mar-12 6:45
GParkings6-Mar-12 6:45 
GeneralRe: How do you enforce use of dedicated factories? Pin
SledgeHammer016-Mar-12 6:56
SledgeHammer016-Mar-12 6:56 
AnswerRe: How do you enforce use of dedicated factories? Pin
jschell6-Mar-12 8:48
jschell6-Mar-12 8:48 
AnswerRe: How do you enforce use of dedicated factories? Pin
jschell6-Mar-12 8:56
jschell6-Mar-12 8:56 
AnswerRe: How do you enforce use of dedicated factories? Pin
Clifford Nelson6-Mar-12 14:26
Clifford Nelson6-Mar-12 14:26 

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.