Click here to Skip to main content
15,884,298 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: I wanna create Architecture using EDMX,WCF and Generics Pin
jschell13-Mar-12 10:29
jschell13-Mar-12 10:29 
AnswerRe: I wanna create Architecture using EDMX,WCF and Generics Pin
Luc Pattyn13-Mar-12 10:57
sitebuilderLuc Pattyn13-Mar-12 10:57 
QuestionWhat is the correct location to inject objects while using dependency injection? Pin
SSEAR6-Mar-12 16:11
SSEAR6-Mar-12 16:11 
AnswerRe: What is the correct location to inject objects while using dependency injection? Pin
walterhevedeich6-Mar-12 19:08
professionalwalterhevedeich6-Mar-12 19:08 
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 
Hi,

I have been trying to refactor the legacy code and make it loosly coupled.
I came across a class which resembles as shown below.

<pre lang="c#">
public Class MyClass
{
private int _a;
private ushort _b;
private int _c;

public MyClass(int a, ushort b, int c)
{
_a = a;
_b = b;
_c = c;
}

public static MyClass FromBytes(byte[] params)
{
int a = BitConverter.ToInt32(params, 0);
ushort b = BitConverter.ToUInt16(params, 1);
int c = BitConverter.ToInt32(params, 2);

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

public int A
{
get
{
return _a;
}
set
{
_a = value;
}
}
}

public Class MyConsumer
{
public void MyMethod()
{
// 1st way to create an instance
MyClass myClass1 = new MyClass(2, 3, 4);
int a = myClass1.A;

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

'MyClass' has been created in two ways.
- creating an instance using a 'new' operator.
- Through a static method 'FromBytes'.

As seen above MyClass is tightly coupled to MyConsumer class.
I need to provide an abstraction for MyClass.

I thought of creating an Inteface 'IMyClass' which has a property 'A'.

<pre lang="c#">
interface IMyClass
{
int A { get; set;}
}
</pre>

MyClass shall have 2 overloaded constructor as shown below.

<pre lang="c#">
public Class MyClass : IMyClass
{
private int _a;
private ushort _b;
private int _c;

public MyClass(int a, ushort b, int c)
{
_a = a;
_b = b;
_c = c;
}

public MyClass(byte[] params)
{
_a = BitConverter.ToInt32(params, 0);
_b = BitConverter.ToUInt16(params, 1);
_c = BitConverter.ToInt32(params, 2);
}

public int A
{
get
{
return _a;
}
set
{
_a = value;
}
}
}
</pre>

I wanted to create an instance of MyClass in MyConsumer class through
some creational pattern such as Factory.
I don't know how to create an instance of a class which has its constructor
overloaded.

Questions:
- How to provide abstraction to static methods?
- How to create an instance of a class which has its constructor overloaded?

I found this link useful, however it does not server my purpose of creating an object through a factory.

Kindly share your view on this and let me know if you need more information.

Thanks in advance!
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 
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 

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.