Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
GeneralRe: System.Security.Cryptography.ProtectedData Does Not Exist Pin
Dave Kreskowiak12-Dec-07 8:54
mveDave Kreskowiak12-Dec-07 8:54 
GeneralRe: System.Security.Cryptography.ProtectedData Does Not Exist Pin
Skippums12-Dec-07 9:05
Skippums12-Dec-07 9:05 
GeneralRe: System.Security.Cryptography.ProtectedData Does Not Exist Pin
Dave Kreskowiak12-Dec-07 12:41
mveDave Kreskowiak12-Dec-07 12:41 
GeneralRe: System.Security.Cryptography.ProtectedData Does Not Exist Pin
Sathesh Sakthivel12-Dec-07 9:01
Sathesh Sakthivel12-Dec-07 9:01 
QuestionPrinting an image in the middle of a page Pin
devzav12-Dec-07 6:40
devzav12-Dec-07 6:40 
GeneralRe: Printing an image in the middle of a page Pin
Paul Conrad23-Dec-07 9:57
professionalPaul Conrad23-Dec-07 9:57 
GeneralRe: Printing an image in the middle of a page Pin
devzav23-Dec-07 10:35
devzav23-Dec-07 10:35 
QuestionUsing Interfaces to force the creation of methods Pin
Clive D. Pottinger12-Dec-07 6:21
Clive D. Pottinger12-Dec-07 6:21 
I am not sure if I am not understanding the use of interfaces or just going about this the wrong way. Any help would be appreciated. Here is the gist of what I am trying to do:

I have a class - Dog - which implements a few basic methods such as tail-wagging and slipper chewing:
class Dog {<br />
  void wagTail(){...};<br />
  void chewSlippers(){...};<br />
}


Now I wish to create a bunch of types of dogs, so:
class doberman : Dog {...)<br />
class labrador : Dog {...}<br />
class chihuaha : Dog {...}<br />
etc.


So far so good. Dobermans, labs and chihuahas can all wag their tails and chew slippers. But I also want dogs to be able to do a trick, so I thought I would force the programmer to create the doTrick method by making it an interface:
interface IDog {<br />
  void doTrick();<br />
}


Here is my problem. The programmer is going to deal with the instances of dogs as part of a collection, so he is not necessarily going to know if the object being used is a doberman or a labrador or what. e.g. the code may look like:
foreach ( Dog myDog in AllDogsInMyHouse ) {...};

If I implement the interface on the individual classes
class doberman : Dog, IDog {...)<br />
class labrador : Dog, IDog {...}<br />
class chihuaha : Dog, IDog {...}<br />
etc.

the programmer must create the doTrick() method for each one - great. But the programmer isn't able to call myDog.doTrick() because doTrick is not defined for the class myDog.

If, instead, I implement the interface on the class myDog
class Dog : IDog {<br />
  void wagTail(){...};<br />
  void chewSlippers(){...};<br />
  void doTrick(){...};<br />
}

the programmer can call myDog.doTrick(), but I now have to provide a default method for doTrick() which is automatically inherited by doberman, labrador, etc. This defeats the purpose - the programmer is not forced to create a doTrick() himself.

Is there a way for me to accomplish both goals?

Clive Pottinger
Victoria, BC

GeneralRe: Using Interfaces to force the creation of methods Pin
Skippums12-Dec-07 6:44
Skippums12-Dec-07 6:44 
GeneralRe: Using Interfaces to force the creation of methods Pin
Clive D. Pottinger12-Dec-07 7:06
Clive D. Pottinger12-Dec-07 7:06 
GeneralRe: Using Interfaces to force the creation of methods Pin
Judah Gabriel Himango12-Dec-07 9:02
sponsorJudah Gabriel Himango12-Dec-07 9:02 
GeneralRe: Using Interfaces to force the creation of methods Pin
Pete O'Hanlon12-Dec-07 11:06
mvePete O'Hanlon12-Dec-07 11:06 
GeneralSplash Screen Shows Black before Showing Pin
Sukhjinder_K12-Dec-07 5:55
Sukhjinder_K12-Dec-07 5:55 
GeneralRe: Splash Screen Shows Black before Showing Pin
Luc Pattyn12-Dec-07 7:23
sitebuilderLuc Pattyn12-Dec-07 7:23 
GeneralRemoving base.OnPaint(e) still does not help Pin
Sukhjinder_K12-Dec-07 16:22
Sukhjinder_K12-Dec-07 16:22 
GeneralRe: Removing base.OnPaint(e) still does not help Pin
Luc Pattyn13-Dec-07 7:22
sitebuilderLuc Pattyn13-Dec-07 7:22 
GeneralBut my Image is Non-Rectangular Pin
Sukhjinder_K13-Dec-07 22:11
Sukhjinder_K13-Dec-07 22:11 
GeneralGraphicsPaths and Scrolling Pin
DahrkDaiz12-Dec-07 5:38
DahrkDaiz12-Dec-07 5:38 
GeneralRe: GraphicsPaths and Scrolling Pin
Paul Conrad23-Dec-07 9:57
professionalPaul Conrad23-Dec-07 9:57 
GeneralCell phones application using c#.net Pin
mostafa_h12-Dec-07 5:26
mostafa_h12-Dec-07 5:26 
GeneralRe: Cell phones application using c#.net Pin
Sathesh Sakthivel12-Dec-07 6:57
Sathesh Sakthivel12-Dec-07 6:57 
GeneralRe: Cell phones application using c#.net Pin
mostafa_h12-Dec-07 9:49
mostafa_h12-Dec-07 9:49 
Generalc# event log size Pin
oi12-Dec-07 5:19
oi12-Dec-07 5:19 
GeneralDynamically instantiating a type and validating interface implementation Pin
Le centriste12-Dec-07 4:49
Le centriste12-Dec-07 4:49 
GeneralRe: Dynamically instantiating a type and validating interface implementation Pin
led mike12-Dec-07 5:11
led mike12-Dec-07 5:11 

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.