Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: Disposing a custom class Pin
Colin Angus Mackay25-Aug-08 13:40
Colin Angus Mackay25-Aug-08 13:40 
GeneralRe: Disposing a custom class Pin
Vodstok25-Aug-08 13:29
Vodstok25-Aug-08 13:29 
GeneralRe: Disposing a custom class Pin
Colin Angus Mackay25-Aug-08 13:41
Colin Angus Mackay25-Aug-08 13:41 
GeneralRe: Disposing a custom class Pin
Vodstok25-Aug-08 13:48
Vodstok25-Aug-08 13:48 
GeneralRe: Disposing a custom class Pin
Colin Angus Mackay25-Aug-08 13:56
Colin Angus Mackay25-Aug-08 13:56 
GeneralRe: Disposing a custom class Pin
Vodstok25-Aug-08 14:13
Vodstok25-Aug-08 14:13 
QuestionCan an object cast itself to a derived class? Pin
Togakangaroo25-Aug-08 10:32
Togakangaroo25-Aug-08 10:32 
AnswerRe: Can an object cast itself to a derived class? Pin
Colin Angus Mackay25-Aug-08 10:48
Colin Angus Mackay25-Aug-08 10:48 
Togakangaroo wrote:
This is 50% curiousity, 50% because I might want to do this (so if this is a 'DON'T DO THIS EVER' type thing, by all means tell me) but I don't even know if its possible.


Code in the base class can cast itself to a derived class IF (AND ONLY IF) the object is actually an instance of the derived class in the first place.

HOWEVER, (and you're way ahead of me), this is a "DON'T DO THIS EVER" type of thing. The base class should have no knowledge of its derived classes. It is the responsibility of the derived class to know about its base.

If a base class uses information about derived classes then you lock the base class effectively. The base is no longer open to extension by other new derived classes at a later date. Any new derived class would potentially require changes in the base. This is bad.


Togakangaroo wrote:
Is it possible for CheckOut() to transform the book input into it so it is now a CheckedOutBook?


This is a different question. CheckOut is a method on Library which is not in the same class heirarchy as Book and CheckedOutBook.

You have a ref Book b in the method signature, so I suppose you could REPLACE b with a CheckedOutBook but not transform the existing one. Also I consider using ref and out to be poor practice. In an OO system there are many better ways to accomplish the same thing. I see that there is no return value for the method so there really is no reason at all to be using ref as you can do that through the return value.

Also, the implication of CheckedOutBook is that you are assigning state (whether the book is checked out or not) to the class. State should be a property of the class, not the reason d'etre of the class.

I hope this helps.


GeneralRe: Can an object cast itself to a derived class? Pin
Togakangaroo25-Aug-08 11:00
Togakangaroo25-Aug-08 11:00 
AnswerRe: Can an object cast itself to a derived class? Pin
chaiguy133725-Aug-08 14:50
chaiguy133725-Aug-08 14:50 
QuestionHow can I add a button here ? Pin
Mohammad Dayyan25-Aug-08 10:01
Mohammad Dayyan25-Aug-08 10:01 
AnswerRe: How can I add a button here ? Pin
DaveyM6925-Aug-08 10:19
professionalDaveyM6925-Aug-08 10:19 
AnswerRe: How can I add a button here ? Pin
Thomas Stockwell26-Aug-08 2:16
professionalThomas Stockwell26-Aug-08 2:16 
QuestionPassing array to operator overload Pin
DaveyM6925-Aug-08 9:48
professionalDaveyM6925-Aug-08 9:48 
AnswerRe: Passing array to operator overload Pin
DaveyM6925-Aug-08 10:21
professionalDaveyM6925-Aug-08 10:21 
GeneralRe: Passing array to operator overload Pin
chaiguy133725-Aug-08 14:53
chaiguy133725-Aug-08 14:53 
QuestionEnum / Cast Question Pin
Kevin Marois25-Aug-08 7:56
professionalKevin Marois25-Aug-08 7:56 
AnswerRe: Enum / Cast Question Pin
User 665825-Aug-08 8:12
User 665825-Aug-08 8:12 
AnswerRe: Enum / Cast Question Pin
TheFM23425-Aug-08 8:22
TheFM23425-Aug-08 8:22 
AnswerRe: Enum / Cast Question Pin
Mark Salsbery25-Aug-08 8:22
Mark Salsbery25-Aug-08 8:22 
AnswerRe: Enum / Cast Question Pin
DaveyM6925-Aug-08 9:03
professionalDaveyM6925-Aug-08 9:03 
QuestionRe: Enum / Cast Question Pin
chaiguy133725-Aug-08 14:55
chaiguy133725-Aug-08 14:55 
AnswerRe: Enum / Cast Question Pin
N a v a n e e t h25-Aug-08 18:13
N a v a n e e t h25-Aug-08 18:13 
AnswerRe: Enum / Cast Question Pin
DaveyM6925-Aug-08 23:10
professionalDaveyM6925-Aug-08 23:10 
GeneralRe: Enum / Cast Question Pin
chaiguy133726-Aug-08 4:42
chaiguy133726-Aug-08 4:42 

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.