OK thanks for that gents. How about a good example in an e-commerce
A lot of the time you can get classes to implement an interface rather than
having to create an abstract class and override abstract methods in
descendant classes. When it comes to mapping objects to a database, as long
as your persistence framework supports inheritance you are much more likely
to use an abstract class in this area.
Imagine an app that schedules jobs to be run on machines.
Key: [ClassName] (RoleName)
[Machine] -----> 0..* (Jobs) [Job]
The Job class might have something like
01: A description
02: When it was last run
03: How often to run it
04: An abstract "Execute" method
You might then have concrete descendants such as
BackupDatabaseJob
RestoreDatabaseJob
CopyFilesJob
DeleteFilesJob
SendEmailJob
and so on. You could even have a descendant of "Job" named "CompositeJob"
which has a reference back to Job
[CompositeJob] -----> 0..* (ChildJobs) [Job]
public class CompositeJob : Job
{
public override void Execute(Machine machine)
{
foreach(Job currentJob in ChildJobs)
currentJob.Execute(machine);
}
}
For in-memory only objects you could do all of this with interfaces, but
when you introduce object persistence you need to use abstract classes
because (as far as I know) there are no OPF's yet which persist associations
to interfaces.