Click here to Skip to main content
15,902,492 members
Home / Discussions / C#
   

C#

 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 13:14
leppie8-Mar-03 13:14 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 13:43
moredip8-Mar-03 13:43 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 13:53
moredip8-Mar-03 13:53 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 14:10
moredip8-Mar-03 14:10 
GeneralRe: Inherited Static Constructors Pin
leppie8-Mar-03 14:25
leppie8-Mar-03 14:25 
GeneralRe: Inherited Static Constructors Pin
moredip8-Mar-03 16:05
moredip8-Mar-03 16:05 
GeneralRe: Inherited Static Constructors Pin
leppie9-Mar-03 7:02
leppie9-Mar-03 7:02 
GeneralRe: Inherited Static Constructors Pin
moredip9-Mar-03 7:26
moredip9-Mar-03 7:26 
I don't think I'm explaining myself very well here Smile | :)

I see what you're saying about having util classes with static methods, rather than inheritance, but I like the idea of having both in the same class. It means only specifying things like tableName and PKName once (rather than once in the instance-base class and once in the util class). And as these are stored in the class, one can use polymorphism to delete a row from a table (for example) without having to know what kind of table it is.

Unfortunately, it seems that we're both agreed that this just isn't possible in C#. So i've make the relevant variable readonly properties that always return the same value, e.g.:
class DBData 
{
    virtual protected string tableName{ get{ return ""; } };
    ....
    ....

}

class AuthorData : DBData
{
    override protected string tableName{ get{ return "Author"; } }
    ....
    ....
}

Now I can write functions like Delete( uint rowID ) in the base class, and via polymorphism they DELETE from different tables depending on what the type the instantiating class is.

This seems less clean to me than using static functions, but it does the job.

RE: placing static and instance in the same sentence, you're quite right. I was using the wrong terminology there. What I meant when i referred to the instantiating class was the class used to call the static method: e.g. with ChildA.SomeMethod() ChildA would be the instantiating class, even though the method is only declared in the base class. Do you see what I mean that with static inheritance polymorphism (which I think could just be a fancy way of saying genericity), the method would behave differently depending on what class was used to call it. E.g. ChildA.SomeStaticMethod() would have different results to ChildB.SomeStaticMethod(), even if neither redefined the method, but simply redefined so static variables.

Oh, and you're right about the static Delete function not making sense. I meant to say that it would be Delete( uint rowID ), where you specify the row you want to delete as a parameter. It seems a bit silly to me to instantiate an entire object just so you can set its rowID and then delete it Smile | :)

I hope I've cleared that up a bit. Sorry, I'm terrible at expressing my ideas on 'paper'!

I'm still working on a solution to this using readonly properties - and I might have to dirty my hands a little with Reflection (not sure yet). If you'd like I can send you my code so you can get some idea what I'm working towards.
GeneralRe: Inherited Static Constructors Pin
leppie9-Mar-03 7:54
leppie9-Mar-03 7:54 
GeneralTextBox DataBinding Pin
leppie8-Mar-03 7:24
leppie8-Mar-03 7:24 
GeneralRe: TextBox DataBinding Pin
leppie8-Mar-03 7:31
leppie8-Mar-03 7:31 
GeneralDocking Problem Pin
Mazdak8-Mar-03 7:02
Mazdak8-Mar-03 7:02 
GeneralRe: Docking Problem Pin
leppie8-Mar-03 7:19
leppie8-Mar-03 7:19 
GeneralRe: Docking Problem Pin
Mazdak8-Mar-03 8:15
Mazdak8-Mar-03 8:15 
GeneralRe: Docking Problem Pin
leppie8-Mar-03 8:25
leppie8-Mar-03 8:25 
GeneralRe: Docking Problem Pin
Roger Alsing8-Mar-03 11:33
Roger Alsing8-Mar-03 11:33 
GeneralRe: Docking Problem Pin
leppie8-Mar-03 12:08
leppie8-Mar-03 12:08 
GeneralRe: Docking Problem Pin
Mazdak8-Mar-03 17:53
Mazdak8-Mar-03 17:53 
QuestionAnything Like MFC's CWinThread in C#? Pin
Xytme8-Mar-03 6:33
Xytme8-Mar-03 6:33 
AnswerRe: Anything Like MFC's CWinThread in C#? Pin
Mazdak8-Mar-03 7:04
Mazdak8-Mar-03 7:04 
QuestionAnything Like MFC's CWinThread in C#? Pin
Xytme8-Mar-03 6:33
Xytme8-Mar-03 6:33 
AnswerRe: Anything Like MFC's CWinThread in C#? Pin
David Stone8-Mar-03 6:44
sitebuilderDavid Stone8-Mar-03 6:44 
QuestionIs there anything like MFC's CWinThread in C#? Pin
Xytme8-Mar-03 6:31
Xytme8-Mar-03 6:31 
QuestionIs there anything like MFC's CWinThread in C#? Pin
Xytme8-Mar-03 6:30
Xytme8-Mar-03 6:30 
AnswerRe: Is there anything like MFC's CWinThread in C#? Pin
David Stone8-Mar-03 6:44
sitebuilderDavid Stone8-Mar-03 6:44 

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.