Click here to Skip to main content
15,921,774 members
Home / Discussions / C#
   

C#

 
GeneralRe: picture box - help!! Pin
printscreen1234526-Jun-06 23:39
printscreen1234526-Jun-06 23:39 
AnswerRe: picture box - help!! Pin
Nader Elshehabi25-Jun-06 11:10
Nader Elshehabi25-Jun-06 11:10 
GeneralRe: picture box - help!! Pin
printscreen1234527-Jun-06 3:20
printscreen1234527-Jun-06 3:20 
GeneralRe: picture box - help!! Pin
Nader Elshehabi27-Jun-06 11:17
Nader Elshehabi27-Jun-06 11:17 
Questionhow to decrypt encryption video in stream and play it ? Pin
hdv21225-Jun-06 3:24
hdv21225-Jun-06 3:24 
QuestionBit of design advice needed Pin
relaeir25-Jun-06 2:02
relaeir25-Jun-06 2:02 
AnswerRe: Bit of design advice needed [modified] Pin
Graham Nimbley25-Jun-06 10:21
Graham Nimbley25-Jun-06 10:21 
AnswerRe: Bit of design advice needed Pin
Richard Houltz25-Jun-06 12:41
Richard Houltz25-Jun-06 12:41 
I read your question and here are some of my thoughts from the top of my head...

I think what you suggest would be a really good approach if you anticipate having a lot of validation and stuff going on.

>You can't assign these without the 'new' keyword in C# though, right?
That's right however you can hide the 'new' call inside an static public method in
the class that you want to create. This is part of the approach when implementing the singleton pattern in C#.

If you like you can add static methods that create your information classes if you think it is ugly with the 'new' keyword. By using this approach you can be more precise about how the object is initialized than if you use oveloaded constructors (where you would have to look up the parameters for the constructor).

For instance
StateInfo stateInfo = StateInfo.LoadFromXml("state.xml");
might be better than
StateInfo stateInfo = new StateInfo("state.xml");

By using a class for each type of information you can also make use of an refactoring called the "Null Object". This means that instead of initializing your StateInfo members to null, you set them to StateInfo.Empty. Now any checks for null is unneccessary and you can implement default values for when the info is missing. For instance the ToString metod return "<no state="" info="" entered="">" or something. This can lead to simpler and more readable code.

If you want to Load any validation RegEx or something for the class you could do that in a static constructor. A static constructor is called once (and only once) when the class is accessed the first time (even if it is through static functions).


Some sample (pseudo-)code:


class StateInfo
{
string m_StateName;

public static StateInfo Empty = new StateInfo("<no state="" entered="">");
public static StateInfo LoadFromXml(string xmlFileName)
{
StateInfo stateInfo = new StateInfo("");
//Init the stateInfo from file...
return stateInfo;
}

public StateInfo(string stateName)
{
//Do instance initialization here
m_StateName = stateName;
}

public static StateInfo()
{
//Called once
//Do class initalization here
}

public override string ToString()
{
return m_StateName;
}
}


So go ahead and use a storage class for your different types of information. I would however recommend that you don't "over design" your system to begin with. Instead go with a light design and refactor it as you go along.

Just some advice as requested, I hope it makes sense!

Have fun!

/Richard
AnswerRe: Bit of design advice needed Pin
relaeir25-Jun-06 18:03
relaeir25-Jun-06 18:03 
Questionsongs off the iPod Pin
ahmedelshafee25-Jun-06 1:26
ahmedelshafee25-Jun-06 1:26 
AnswerRe: songs off the iPod Pin
Paresh Gheewala25-Jun-06 1:42
Paresh Gheewala25-Jun-06 1:42 
QuestionControls on a window Pin
XeoN-Kc25-Jun-06 1:10
XeoN-Kc25-Jun-06 1:10 
AnswerRe: Controls on a window Pin
NaNg1524125-Jun-06 2:31
NaNg1524125-Jun-06 2:31 
QuestionstatusBar help Pin
foysal mamun24-Jun-06 22:19
foysal mamun24-Jun-06 22:19 
AnswerRe: statusBar help Pin
mav.northwind24-Jun-06 23:36
mav.northwind24-Jun-06 23:36 
GeneralRe: statusBar help Pin
foysal mamun24-Jun-06 23:37
foysal mamun24-Jun-06 23:37 
QuestionWhy the WebBrowser vertical scrollbar is always shown? Pin
AngryC24-Jun-06 20:09
AngryC24-Jun-06 20:09 
AnswerRe: Why the WebBrowser vertical scrollbar is always shown? Pin
Stephen Hewitt24-Jun-06 21:36
Stephen Hewitt24-Jun-06 21:36 
AnswerRe: Why the WebBrowser vertical scrollbar is always shown? Pin
Guffa25-Jun-06 0:27
Guffa25-Jun-06 0:27 
GeneralRe: Why the WebBrowser vertical scrollbar is always shown? Pin
AngryC25-Jun-06 5:18
AngryC25-Jun-06 5:18 
QuestionHow can I disable selecting text from my WebBrowser control and drop it in another app? Pin
AngryC24-Jun-06 20:08
AngryC24-Jun-06 20:08 
AnswerRe: How can I disable selecting text from my WebBrowser control and drop it in another app? Pin
Stephen Hewitt24-Jun-06 21:55
Stephen Hewitt24-Jun-06 21:55 
Questionwant ot request a web page from a win app Pin
foysal mamun24-Jun-06 19:01
foysal mamun24-Jun-06 19:01 
AnswerRe: want ot request a web page from a win app Pin
Tamimi - Code24-Jun-06 20:15
Tamimi - Code24-Jun-06 20:15 
GeneralRe: want ot request a web page from a win app Pin
foysal mamun24-Jun-06 20:41
foysal mamun24-Jun-06 20:41 

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.