This site requires JavaScript, please enable it in your browser!
Greenfoot back
darkmist255
darkmist255 wrote ...

2012/1/5

Just curiosity: What is the purpose of abstract classes/methods?

darkmist255 darkmist255

2012/1/5

#
Just for learning sake, I'm curious as to the purpose of an abstract class/method. So far, I think I know that it is a class that can't be called on in itself, but any regular classes that extend it can be called and will inherit from the abstract superclass. Would the "Actor" class be an abstract class? If it is just this, are there really any realistic uses for it? By the way, if abstract classes are some cosmic insane magic thing (aka something I would have no chance of understanding) don't bother trying to explain :D.
mjrb4 mjrb4

2012/1/5

#
Think of it as a partially complete class - you have to extend it to provide the functionality that it lacks before you can use it. Often such a class contains abstract methods that have to be implemented in the subclass, though sometimes a class is marked abstract just to prevent people instantiating it directly. Actor is one such example, it has no abstract methods that need to be implemented but it makes no sense to create a generic "Actor" - you always want a subclass of it. They're useful to avoid code duplication primarily - think of all the methods in Actor that you have for free whenever you create a subclass (move() for instance.) You don't ever create an actor directly but it contains functionality that's useful to each subclass of actor.
darkmist255 darkmist255

2012/1/6

#
Whoa, I actually was closer than I thought :D! Thanks!
You need to login to post a reply.