NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
Base classes should only have functions that are general for all child classes

correct but only partially.
What if I need OBJECT to be parent for FLYINGOBJECT, DRIVINGOBJECT, SWIMMINGOBJECT and DIGGINGOBJECT?
They all are supposed to have MOVE and all their children will have DRAW. Why not to have the two in their parent?
What if my system manages such objects and ask them to move and to draw?

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
dmitri wrote:
Quote:
Base classes should only have functions that are general for all child classes

correct but only partially.
What if I need OBJECT to be parent for FLYINGOBJECT, DRIVINGOBJECT, SWIMMINGOBJECT and DIGGINGOBJECT?
They all are supposed to have MOVE and all their children will have DRAW. Why not to have the two in their parent?
What if my system manages such objects and ask them to move and to draw?


Well if they are all to have the function MOVE, and MOVE can not be implemented on OBJECT then it is declared abstract and MUST be implemented on FLYING,DRIVING,SWIMMING,DIGGINOBJECT.

If you mean that subclasses of FLYING,DRIVING,SWIMMING,DIGGINOBJECT will need DRAW, then you create an interface for the DRAW method and let the child classes implement the interface.

This is a basic problem with multiple inheritence in OOP.

Please not in the article that I included the URL to you will find this text.

Because the class is abstract, an instance of it can never be created (remember, it is only a partial implementation). Instead a child class must be created using inheritance and implement the fire method in itself. Failure to do so will result in a fatal error. Listing 2 shows a child class being created from the Abstract Weapon class.

So if you do not implement all abstract functions on child classes you will get a FATAL error. If you had a compile like feature, then you will be able to avoid this by "compiling" your code.
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
well, I finally see you agree with this
Quote:
Because the class is abstract, an instance of it can never be created

and this is the problem I begun with. The key word is "created" which clearly indicates "run-time".
Only statements like this $a=new SomeClass() can be recognized in compile-time.
And you can never guarantee if developer is not using __autoload() and if this SomeClass is abstract used while there are may be two or more classes with the same name and they are not abstract...

In other words, checks for simple cases can be automated but it's not what most people want to have. They need checks for non-simple situations when they can't get problems resolved on theirown.

What I'd mostly care of is a good testing system. BTW without such system you'd not get PhpED 5.0 with Code Folding in April 2007 Smile

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
A copmile like feature. (Run instant error analysis)
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 2 of 2  

  
  
 Reply to topic