Click here to Skip to main content
15,886,055 members
Home / Discussions / C#
   

C#

 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 1:28
Colin Angus Mackay1-Feb-04 1:28 
GeneralRe: Automatically creating classes ? Pin
Andres Coder1-Feb-04 2:57
Andres Coder1-Feb-04 2:57 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 3:42
Colin Angus Mackay1-Feb-04 3:42 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu1-Feb-04 9:05
Arjan Einbu1-Feb-04 9:05 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 9:48
Colin Angus Mackay1-Feb-04 9:48 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu1-Feb-04 22:04
Arjan Einbu1-Feb-04 22:04 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay2-Feb-04 1:33
Colin Angus Mackay2-Feb-04 1:33 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu2-Feb-04 3:26
Arjan Einbu2-Feb-04 3:26 
Colin Angus Mackay wrote:
If all you do in the property getter is return the member variable (field) then there isn't much difference.
Smile | :) You did in your example... Poke tongue | ;-P ;)


I know the rules of OO, but i believe rules can be broken sometimes if it serves a greater purpose. (Less code, fewer sources of error, greater maintainability.)

You're absolutely right that you might want to change your code later on, and if other assemblies access my field, they will need to be recompiled if that field later on is changed to a property. So if some other assemblies are going to use that singleton, one should consider wrapping it up in a property, as you say, Colin.
(Also, public fields cannot be made part of an interface definition, so there can be several reasons to make it a property.)

However, if the field is accessed only from within the same assembly (or assemblies that are compiled together with the containing assembly) it will make no difference if you change the field to a property. This is very often the case. (Though one should perhaps mark the property as internal instead of public in that case.)

Encapsulation is preserved i this construct. By making the instance constructor private, we make sure there will be made no other instances of the singleton.
Revealing the inner workings on this construct wont do any harm. The knowledge gained from it can't be abused to access inner data in other ways than the way we planned for.



Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay2-Feb-04 4:08
Colin Angus Mackay2-Feb-04 4:08 
GeneralRe: Automatically creating classes ? Pin
Arjan Einbu2-Feb-04 4:36
Arjan Einbu2-Feb-04 4:36 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 1:35
Colin Angus Mackay1-Feb-04 1:35 
GeneralRe: Automatically creating classes ? Pin
Andres Coder1-Feb-04 4:47
Andres Coder1-Feb-04 4:47 
GeneralRe: Automatically creating classes ? Pin
Colin Angus Mackay1-Feb-04 5:01
Colin Angus Mackay1-Feb-04 5:01 
QuestionVirtual colums in a datagrid? Pin
Franz Pentenrieder31-Jan-04 12:02
Franz Pentenrieder31-Jan-04 12:02 
AnswerRe: Virtual colums in a datagrid? Pin
Heath Stewart2-Feb-04 4:21
protectorHeath Stewart2-Feb-04 4:21 
GeneralQuick answer for threading Pin
jacal9931-Jan-04 11:35
jacal9931-Jan-04 11:35 
GeneralRe: Quick answer for threading Pin
OmegaSupreme1-Feb-04 5:37
OmegaSupreme1-Feb-04 5:37 
GeneralProblem with events (I think) ... Pin
Andres Coder31-Jan-04 9:14
Andres Coder31-Jan-04 9:14 
GeneralRe: Problem with events (I think) ... Pin
Mazdak31-Jan-04 9:31
Mazdak31-Jan-04 9:31 
GeneralA drawing method parameters ... Pin
Andres Coder31-Jan-04 2:44
Andres Coder31-Jan-04 2:44 
GeneralRe: A drawing method parameters ... Pin
Mazdak31-Jan-04 4:36
Mazdak31-Jan-04 4:36 
GeneralRe: A drawing method parameters ... Pin
Nick Parker31-Jan-04 4:44
protectorNick Parker31-Jan-04 4:44 
Questionwhere is "Project Settings (ALT+F7)" of VC++6.0 in VS.NET ?? Pin
Anonymous31-Jan-04 2:17
Anonymous31-Jan-04 2:17 
AnswerRe: where is "Project Settings (ALT+F7)" of VC++6.0 in VS.NET ?? Pin
22491731-Jan-04 2:50
22491731-Jan-04 2:50 
AnswerRe: where is "Project Settings (ALT+F7)" of VC++6.0 in VS.NET ?? Pin
Mazdak31-Jan-04 4:45
Mazdak31-Jan-04 4: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.