There is no point in adding a function to a class that does not require it. It would defeat the point of your inheritance I'd do a safe cast var I = obj as theClass and then test for null. I'd use a bit of linq to select all o the objects that have the property you defined to indicate what type they are set to true You could do it the other way and save yourself the cast and test, but it means the design is less obvious to an outsider I think its a matter of taste but prefer the way you did it.
I am not sure I like the bool properties to identify the type though. What if you inherit off the base class again? Besides you can cast to identify the type - which with a deeper object structure may be more useful I agree with your desire to work with a collection of the abstract class though.
There is no point in adding a function to a class that does not require it. It would defeat the point of your inheritance. I'd do a safe cast ... var I = obj as theClass and then test for null.
I'd use a bit of linq to select all o the objects that have the property you defined to indicate what type they are set to true. You could do it the other way and save yourself the cast and test, but it means the design is less obvious to an outsider. I think its a matter of taste but prefer the way you did it.
I am not sure I like the bool properties to identify the type though. What if you inherit off the base class again? Besides you can cast to identify the type - which with a deeper object structure may be more useful.
I agree with your desire to work with a collection of the abstract class though.
I did the cast, it seemed the best way at the time, but it could be a better way. When it comes to the bool properties I was just looking for a quick way to determine if the wrapper object can schedule activities or not, without casting. That way I would just dismiss the cases where the user clicks on an already scheduled activity.
But it kind of felt funky yeah...So in your opinion I'm better off casting the wrapper? – Jay Nov 1 '10 at 14:38 yeah definatley. I tend to code against interfaces for IOC reasons - they also tend to solve problems that I haven't spotted at the time.
The abstract class is functionally the same here (well you implement tostring but apart from that its basically an interface). So I think the solution with the attempt to cast is reliable - its a technique thats worked well for me. I wouldn't recommend adding the redundant method - that is for sure as it could confuse anyone trying to figure out what is going on.
I do think this is a style thing though - I know someone I work with would um and arr over it. – John Nicholas Nov 1 '10 at 23:34 I'll give it a try casting the wrapper. Regarding the abstract class, that's exactly it.
I use it because I have a couple of methods there that come in handy for the common part of the activity objects, otherwise it would definitively be an interface. I just don't like the idea of repeating code in classes if I can abstract out that behavior. – Jay Nov 2 '10 at 10:21.
In the several occasions that I had to deal with a similiar problem, I tend to think that it's really more elegant to create Interfaces for recognizing common functionailty for several objects then to create abstract methods which the inheriting classes will implement the way you mentioned. E.g. Public interface IAppSlotContainer { void relevant_Method_When_ObjectIsAppSlot(); } public interface IEmptySlotContainer { void relevant_Method_When_ObjectIsEmptySlot(); } public class EmptyWrapper : AppWrapper, IAppSlotContainer, IEmptySlotContainer { public EmptyWrapper(EmptySlot emptySlot) : base() { this.
_emptySlot = emptySlot; } public override string Id { get { return _emptySlot. AgendaId; } } public void relevant_Method_When_ObjectIsEmptySlot() { } public void relevant_Method_When_ObjectIsAppSlot() { } } Then instead of overwriting the abstract method "IsEmpty" and implementing it as "return true", just check whether the object is an instance of IEmptySlotContainer, cast it to that interface, and execute the interface related command. It is far more generic and elegant for my taste... Hope this helps...
Hum...i liked it a lot! I will most definitely give it a go! – Jay Jun 21 at 7:41.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.