|
-
Dec 4th, 2003, 02:46 AM
#1
Thread Starter
Frenzied Member
Question about implementing interfaces and properties
I have made a silly test program which works like this(pseudo-code):
Interface IAnimal
sub Eat
sub Sleep
sub Drink
property name as string
property height as integer
I have a class called CAnimal
class CAnimal
private name
private height
get set name
get set height
end class
I have a class that inherits from CAnimal
class CBird : inherits CAnimal
implements IAnimal
'Implement the methods and properties of IAnimal
public sub Fly()
'Make the bird fly
end sub
end class
class CWatcher(byval subject as IAnimal)
Console.Write("The name of the subject is: " & subject.name)
end class
Now, what is the point of all this.. well nothing really, I just made this example to test all the features of vb.net OO, and as you notice there are a few gaps:
1) How can I make the CAnimal class more useful??? It is logical that it should be there but how can I bebefit from it further?
2) How do I make the interface work properly? For example, I don't want the CAnimal Class to implement the methods, only the properties, and the CBird class should only implement the methods because it inherits from CAnimal which implements the properties. Should I create some kind of hierarchy with the interfaces too? I mean, one interface for the animal class, and one interface for the CBird, CWolf, CDog etc...?that only implements the methods that make them unique
3)How do I implement a generic constructor??? What is the best way to implement a constructor in this scenario? I want to use the factory pattern!!
ANyway, I hope someone can take a few minutes to perfect this example, because it really contains almost all features of OO, and I really want to understand this fully...
kind regards
Henrik
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|