Click here to Skip to main content
15,881,600 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: What is the correct location to inject objects while using dependency injection? Pin
SSEAR7-Mar-12 3:01
SSEAR7-Mar-12 3:01 
AnswerRe: What is the correct location to inject objects while using dependency injection? Pin
Mahmud Hasan10-Mar-12 11:01
Mahmud Hasan10-Mar-12 11:01 
AnswerRe: What is the correct location to inject objects while using dependency injection? Pin
RichardGrimmer11-Apr-12 5:49
RichardGrimmer11-Apr-12 5:49 
QuestionRefactor static methods for loose coupling. Pin
Praveen Raghuvanshi3-Mar-12 4:21
professionalPraveen Raghuvanshi3-Mar-12 4:21 
AnswerRe: Refactor static methods for loose coupling. Pin
Bernhard Hiller4-Mar-12 19:59
Bernhard Hiller4-Mar-12 19:59 
GeneralRe: Refactor static methods for loose coupling. Pin
Praveen Raghuvanshi8-Mar-12 8:07
professionalPraveen Raghuvanshi8-Mar-12 8:07 
AnswerRe: Refactor static methods for loose coupling. Pin
jschell5-Mar-12 8:44
jschell5-Mar-12 8:44 
GeneralRe: Refactor static methods for loose coupling. Pin
Praveen Raghuvanshi8-Mar-12 8:21
professionalPraveen Raghuvanshi8-Mar-12 8:21 
Thanks jschell for your time.
As per my understanding based on your inputs, we need to create a factory.
So, in the sample code, it would be something like this.

interface IMyClassFactory
{
IMyClass Create(int a, ushort b, int c);
IMyClass Create(byte[] bytes);
}

and its implementation would be something like this.

public class MyClassFactory : IMyClassFactory
{
public IMyClass Create(int a, ushort b, int c)
{
return new MyClass(a, b, c);
}

public IMyClass Create(byte[] bytes)
{
int a = BitConverter.ToInt32(params, 0);
ushort b = BitConverter.ToUInt16(params, 1);
int c = BitConverter.ToInt32(params, 2);

return new MyClass(a, b, c);
}
}

Consumer:

public Class MyConsumer
{
public void MyMethod()
{
IMyClassFactory myClassFactory = new MyClassFactory(); // we can inject this

// 1st way to create an instance
IMyClass myClass1 = myClassFactory.Create(2, 3, 4);
int a = myClass1.A;

// 2nd way of creating an instance
byte[] bytes = {8, 7, 6};
MyClass myClass2 = myClassFactory.Create(bytes);
int a1 = myClass2.A;
}
}

Please correct me if I have misunderstood something here. Appreciate, if you can explain with a small example.
Is it acceptable to create an overloaded method in a factory as factory takes and parameter which defines the type of object required?
GeneralRe: Refactor static methods for loose coupling. Pin
jschell9-Mar-12 6:03
jschell9-Mar-12 6:03 
QuestionCross platform team structure Pin
Richard Brett27-Feb-12 12:21
Richard Brett27-Feb-12 12:21 
AnswerRe: Cross platform team structure Pin
OChristiaanse29-Feb-12 10:17
OChristiaanse29-Feb-12 10:17 
GeneralRe: Cross platform team structure Pin
Richard Brett29-Feb-12 16:26
Richard Brett29-Feb-12 16:26 
GeneralRe: Cross platform team structure Pin
OChristiaanse29-Feb-12 19:57
OChristiaanse29-Feb-12 19:57 
AnswerRe: Cross platform team structure Pin
RobCroll29-Feb-12 13:52
RobCroll29-Feb-12 13:52 
AnswerRe: Cross platform team structure Pin
jschell1-Mar-12 8:52
jschell1-Mar-12 8:52 
QuestionA project of compiler Pin
Dmitri Novikov27-Feb-12 11:40
Dmitri Novikov27-Feb-12 11:40 
AnswerRe: A project of compiler Pin
R. Giskard Reventlov27-Feb-12 12:29
R. Giskard Reventlov27-Feb-12 12:29 
QuestionData dictionary SQLServer versions Pin
OChristiaanse20-Feb-12 3:38
OChristiaanse20-Feb-12 3:38 
AnswerRe: Data dictionary SQLServer versions Pin
jschell20-Feb-12 10:34
jschell20-Feb-12 10:34 
GeneralRe: Data dictionary SQLServer versions Pin
OChristiaanse21-Feb-12 0:00
OChristiaanse21-Feb-12 0:00 
GeneralRe: Data dictionary SQLServer versions Pin
jschell21-Feb-12 9:31
jschell21-Feb-12 9:31 
GeneralRe: Data dictionary SQLServer versions Pin
OChristiaanse21-Feb-12 20:56
OChristiaanse21-Feb-12 20:56 
GeneralRe: Data dictionary SQLServer versions Pin
jschell22-Feb-12 11:40
jschell22-Feb-12 11:40 
GeneralRe: Data dictionary SQLServer versions Pin
OChristiaanse27-Feb-12 3:41
OChristiaanse27-Feb-12 3:41 
GeneralRe: Data dictionary SQLServer versions Pin
Pete O'Hanlon27-Feb-12 3:45
mvePete O'Hanlon27-Feb-12 3:45 

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.