At 10/5/07 01:17 PM, Gutya wrote:
As far as I can see abstract classes are used to contain code a lot of your other classes will need, but not to be used alone. Am I correct in this?
Yes, you would be correct...more or less. It does not need to be code that you will use in a lot of your other classes though. You could technically only ever extend the abstract class once. The point of abstract classes are to define a base that you can extend, and elaborate on but will always have that basic functionality, if that makes sence.
Example being a template engine. Say you have a abstract class, called TemplateA, ('A' for abstract) that defines the public methods setVariable(), and loadTemplate(). You may want to extend this class to include extra functionality. Regardless of the extra functionality you may add, the setVariable() and loadTemplate() methods will allways act the same, and thus there is no need to re-define them. This is a case where you would use an abstract class.
And I just can't seem to see the point of/understand interfaces at all, if someone could give me a hand in explaining it would be a great help.
Interfaces (as well as abstract classes) come into use more and more as you get into design patterns. Their purpose is to tell the implimenting class of methods that NEED to exist, without having to define them its self.
An example of this might be if you're getting into implimenting a robust data layer. You could define a interface called iData which could contain find(), save() methods. You could then create a new class called MySQL, which would impliment iData. Now the class knows of methods it must contain. You could also create a new class called Oracle, which would impliment iData. The advantage now, is that both classes know the methods it must define. These methods could not, however be defined in iData, as the interface to both MySQL and Oracle are completely different.
These are pretty simple examples, and they may not make sence to you, or anybody else, at all; I don't know. I've tried to explain them best I could.