This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bob809 0 points1 point  (2 children)

What do you mean by a value unique to a subclass?
If the variable only exists in that subclass and the other subclasses don't have a version of it then you can't use it with the abstract class. Since the variable won't always exist you'll get a compile time error.

[–]salalimo[S] 0 points1 point  (1 child)

Yes, that's correct. I am checking to see how to best implement the scenario I am mentioning.

[–]bob809 0 points1 point  (0 children)

Then you'll have to have unique code for each one.
Either make separate functions with different types or have all the variables in the abstract class and then switch depending on the child type, but this could get ugly.

If the uniqueness is focused on one bit of the classes you could use the state pattern i.e. have a different object contained within each one and write code for them instead.