|
Posted by Daedalus.OS on 10/13/68 11:30
And even with, for example, the Math class (static class), would the right
way to go would be to create a normal class with static funtions and a
private constructor (since there can be no instance of that class) rather
than using an abstract class with static functions ?
If I get things right, abstract classes are pretty much like interfaces (at
least in PHP). The difference being that interfaces only declare functions
that need to be defined in the "child" classes and abstract classes can
declare functions (abstract functions) and/or define functions. It probably
not represents the whole picture but am I heading in the right direction ?
Thanks Dae
> Abstract classes are classes of which no object can be instantiated.
> Normally, this is because there is some method left undefined (abstract).
> The meaning of an abstract class is to be a superclass, so a class
> extending from the abstract class can implement what was left undefined.
> This probably sounds very vague, so let me give you an example.
> Suppose you wantr to support more than one database. You could define an
> abstract class called AbstractQuery with a SqlToArray method, that takes a
> string and returns the result of the query as an array. SQL _can_ be
> database independent and arrays are database independent as well, so this
> class could be useful. You could define the method SqlToArray as abstract,
> and create a few more classes: MysqlQuery, OdbcQuery, FirefoxQuery, or
> whatever database you want to support. These classes all extends from the
> AbstractQuery and implement the database-dependent stuff. You could have
> done this also with an interface, as an interface is a purely abstract
> class.
>
> A static class is a class with only static methods. The best example from
> it is the Math class in java. Static classes are stateless: they have no
> data that can distinguish one instance from the other. You login class
> probably _will_ have a state (LoginSucceeded, for instance), so this is
> not a very good option.
>
> Singletons are the global variables of OO programming. I don't like them.
> There is nothing wrong with a class that happens to be the definition of
> just one object.
>
> Gotta go now, more later.
>
>>... For exemple a login class. I've made one as an abstract class and now
>>I'm wondering if it's a good idea. Technically there would be only one
>>login object so I thought having this object was pointless and I use an
>>abstract class with everything in it static. Is it a good or a bad idea
>>and why? In what situation the difference between having only one object
>>and no object at all with only static functions and variables would lead
>>to use one more the other? Or why in a PHP context would I prefer to have
>>a single object rather than what I would call a "static virtual object".
>>
>>
>> Thanks,
>> Dae
Navigation:
[Reply to this message]
|