Click here to Skip to main content
15,912,977 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Why do I listen to my sleep coding self? Pin
kalberts12-Jun-14 21:22
kalberts12-Jun-14 21:22 
GeneralRe: Why do I listen to my sleep coding self? Pin
Richard MacCutchan12-Jun-14 0:43
mveRichard MacCutchan12-Jun-14 0:43 
GeneralRe: Why do I listen to my sleep coding self? PinPopular
harold aptroot12-Jun-14 0:45
harold aptroot12-Jun-14 0:45 
GeneralRe: Why do I listen to my sleep coding self? Pin
BobJanova12-Jun-14 0:55
BobJanova12-Jun-14 0:55 
GeneralRe: Why do I listen to my sleep coding self? Pin
harold aptroot12-Jun-14 1:10
harold aptroot12-Jun-14 1:10 
GeneralRe: Why do I listen to my sleep coding self? Pin
BobJanova12-Jun-14 1:31
BobJanova12-Jun-14 1:31 
GeneralRe: Why do I listen to my sleep coding self? Pin
harold aptroot12-Jun-14 1:43
harold aptroot12-Jun-14 1:43 
GeneralRe: Why do I listen to my sleep coding self? Pin
BobJanova12-Jun-14 2:04
BobJanova12-Jun-14 2:04 
Ok so let's have an example.

public static class BaseService {
 public static void LoadData() {
  Console.WriteLine(GetDataSource());
 } 

 protected virtual static string GetDataSource();
}

public static class FileService : BaseService {
 protected override static string GetDataSource() { return "file.dat"; }
}

public static class DatabaseService : BaseService {
 protected override static string GetDataSource() { return "database"; }
}


... and calling code
void Run() {
 DatabaseService.LoadData();
 FileService.LoadData();
}


This would print "database" and "file.dat", because the class used for the vtable lookups would be taken from the data type used for the call (i.e. DatabaseService.LoadData). That would be resolved at compile time and based on the static declaration type used in the call, not dynamic object type lookups as with instance dispatch.

A related good idea is the ability to pass service classes around and dispatch off them:

void Run(Class<BaseService> service) {
 service.LoadData();
}


... called like Run(DatabaseService) which would bake in the type for dispatch.
GeneralRe: Why do I listen to my sleep coding self? Pin
harold aptroot12-Jun-14 2:17
harold aptroot12-Jun-14 2:17 
GeneralRe: Why do I listen to my sleep coding self? Pin
PIEBALDconsult12-Jun-14 2:55
mvePIEBALDconsult12-Jun-14 2:55 
GeneralRe: Why do I listen to my sleep coding self? Pin
JimmyRopes12-Jun-14 21:55
professionalJimmyRopes12-Jun-14 21:55 
GeneralRe: Why do I listen to my sleep coding self? Pin
PIEBALDconsult13-Jun-14 3:03
mvePIEBALDconsult13-Jun-14 3:03 
GeneralRe: Why do I listen to my sleep coding self? Pin
Paulo Zemek13-Jun-14 4:36
Paulo Zemek13-Jun-14 4:36 
GeneralRe: Why do I listen to my sleep coding self? Pin
SortaCore12-Jun-14 22:06
SortaCore12-Jun-14 22:06 
GeneralRe: Why do I listen to my sleep coding self? Pin
harold aptroot12-Jun-14 22:33
harold aptroot12-Jun-14 22:33 
GeneralRe: Why do I listen to my sleep coding self? Pin
SortaCore12-Jun-14 22:55
SortaCore12-Jun-14 22:55 
GeneralRe: Why do I listen to my sleep coding self? Pin
patbob13-Jun-14 6:22
patbob13-Jun-14 6:22 
GeneralRe: Why do I listen to my sleep coding self? Pin
BobJanova15-Jun-14 23:35
BobJanova15-Jun-14 23:35 
GeneralRe: Why do I listen to my sleep coding self? Pin
Paulo Zemek12-Jun-14 17:04
Paulo Zemek12-Jun-14 17:04 
GeneralRe: Why do I listen to my sleep coding self? Pin
AnnPandora12-Jun-14 0:54
AnnPandora12-Jun-14 0:54 
GeneralRe: Why do I listen to my sleep coding self? Pin
OriginalGriff12-Jun-14 1:01
mveOriginalGriff12-Jun-14 1:01 
GeneralRe: Why do I listen to my sleep coding self? Pin
AnnPandora12-Jun-14 1:07
AnnPandora12-Jun-14 1:07 
GeneralRe: Why do I listen to my sleep coding self? Pin
OriginalGriff12-Jun-14 1:13
mveOriginalGriff12-Jun-14 1:13 
GeneralRe: Why do I listen to my sleep coding self? Pin
AnnPandora12-Jun-14 2:26
AnnPandora12-Jun-14 2:26 
GeneralRe: Why do I listen to my sleep coding self? Pin
OriginalGriff12-Jun-14 2:33
mveOriginalGriff12-Jun-14 2:33 

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.