# Class Properties in Interfaces?

- Thread: https://externals.io/message/37281
- Original archive: https://news-web.php.net/php.internals/37281
- Started by Jeremy Privett on 2008-04-29T03:31:33+00:00
- Messages: 86
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/37281.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #37281 — Jeremy Privett — 2008-04-29T03:31:33+00:00

URL: https://externals.io/message/37281#37281

Hey list,

I was curious what everyone thought of implementing the ability to 
specify class members in interfaces. I've run into a couple of 
circumstances where I would like to specify public member names inside 
of an interface to ensure that these members are accessed in a standard 
way and to ensure that they exist. Currently, trying to include them in 
an interface results in "*Fatal error*: Interfaces may not include 
member variables in file/line number".

Thoughts?

Thanks.

-- 
Jeremy Privett
C.E.O. & C.S.A.
Omega Vortex Corporation

http://www.omegavortex.net

Please note: This message has been sent with information that could be confidential and meant only for the intended recipient. If you are not the intended recipient, please delete all copies and inform us of the error as soon as possible. Thank you for your cooperation.

---

## #37285 — Marcus Boerger — 2008-04-29T09:46:07+00:00

URL: https://externals.io/message/37281#37285 · In reply to: #37281

Hello Jeremy,

  interfaces cannot have properties, nor can they have method bodies - that
is the whole purpose of interfafces. We are thinking of adding traits which
would allow for both but would treat inheritance differently. Until we get
that you would need to provide an abstract interface to access data in the
same way.

marcus

Tuesday, April 29, 2008, 5:31:33 AM, you wrote:

> Hey list,

> I was curious what everyone thought of implementing the ability to 
> specify class members in interfaces. I've run into a couple of 
> circumstances where I would like to specify public member names inside 
> of an interface to ensure that these members are accessed in a standard 
> way and to ensure that they exist. Currently, trying to include them in 
> an interface results in "*Fatal error*: Interfaces may not include 
> member variables in file/line number".

> Thoughts?

> Thanks.

> -- 
> Jeremy Privett
> C.E.O. & C.S.A.
> Omega Vortex Corporation

> http://www.omegavortex.net

> Please note: This message has been sent with information that could be
> confidential and meant only for the intended recipient. If you are not the
> intended recipient, please delete all copies and inform us of the error as
> soon as possible. Thank you for your cooperation.





Best regards,
 Marcus

---

## #37286 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T10:07:53+00:00

URL: https://externals.io/message/37281#37286 · In reply to: #37285

Marcus,

I understand why Interfaces can't have bodies, but could you explain why
Interfaces can't have properties? 

Thanks,

John.

-----Original Message-----
From: Marcus Boerger [mailto:helly@php.net] 
Sent: 29 April 2008 10:46
To: Jeremy Privett
Cc: PHP Developers Mailing List
Subject: Re: [PHP-DEV] Class Properties in Interfaces?

Hello Jeremy,

  interfaces cannot have properties, nor can they have method bodies -
that is the whole purpose of interfafces. We are thinking of adding
traits which would allow for both but would treat inheritance
differently. Until we get that you would need to provide an abstract
interface to access data in the same way.

marcus

Tuesday, April 29, 2008, 5:31:33 AM, you wrote:

> Hey list,

> I was curious what everyone thought of implementing the ability to 
> specify class members in interfaces. I've run into a couple of 
> circumstances where I would like to specify public member names inside

> of an interface to ensure that these members are accessed in a 
> standard way and to ensure that they exist. Currently, trying to 
> include them in an interface results in "*Fatal error*: Interfaces may

> not include member variables in file/line number".

> Thoughts?

> Thanks.

> --
> Jeremy Privett
> C.E.O. & C.S.A.
> Omega Vortex Corporation

> http://www.omegavortex.net

> Please note: This message has been sent with information that could be

> confidential and meant only for the intended recipient. If you are not

> the intended recipient, please delete all copies and inform us of the 
> error as soon as possible. Thank you for your cooperation.





Best regards,
 Marcus


--
 To unsubscribe,
visit: http://www.php.net/unsub.php

---

## #37287 — Sebastian Bergmann — 2008-04-29T10:15:56+00:00

URL: https://externals.io/message/37281#37287 · In reply to: #37286

John Carter -X (johncart - PolicyApp Ltd at Cisco) schrieb:
> could you explain why Interfaces can't have properties

  Because interfaces are implemented which makes no sense for attributes.

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #37288 — James Dempster — 2008-04-29T10:16:47+00:00

URL: https://externals.io/message/37281#37288 · In reply to: #37286

I would start by saying it's bad design. you should use getters and setters
which you can define in you interface

--
/James

On Tue, Apr 29, 2008 at 11:07 AM, John Carter -X (johncart - PolicyApp Ltd
at Cisco) <johncart@cisco.com> wrote:

> Marcus,
>
> I understand why Interfaces can't have bodies, but could you explain why
> Interfaces can't have properties?
>
> Thanks,
>
> John.
>
> -----Original Message-----
> From: Marcus Boerger [mailto:helly@php.net]
> Sent: 29 April 2008 10:46
> To: Jeremy Privett
> Cc: PHP Developers Mailing List
> Subject: Re: [PHP-DEV] Class Properties in Interfaces?
>
> Hello Jeremy,
>
>  interfaces cannot have properties, nor can they have method bodies -
> that is the whole purpose of interfafces. We are thinking of adding
> traits which would allow for both but would treat inheritance
> differently. Until we get that you would need to provide an abstract
> interface to access data in the same way.
>
> marcus
>
> Tuesday, April 29, 2008, 5:31:33 AM, you wrote:
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
>
>
>
>
> Best regards,
>  Marcus
>
>
> --
>  To unsubscribe,
> visit: http://www.php.net/unsub.php

---

## #37289 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T10:22:53+00:00

URL: https://externals.io/message/37281#37289 · In reply to: #37288

It might be bad design, but design is down to the application developer
and not the people who define a language.
 
I'm not necessary asking for the feature, I just want to understand why
we can't do it.
 
John.

---

## #37290 — Sebastian Bergmann — 2008-04-29T10:23:23+00:00

URL: https://externals.io/message/37281#37290 · In reply to: #37288

James Dempster schrieb:
> you should use getters and setters which you can define in interface

  BTW: An attribute with getter and setter is what I would call a
  property.

-- 
Sebastian Bergmann                          http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #37291 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T10:28:14+00:00

URL: https://externals.io/message/37281#37291 · In reply to: #37287

I think I must be missing something here, but this sounds a little
tautological - "we can't do it because it doesn't make sense. This is
because it doesn't make sense"

Certainly most people (myself included) consider interfaces to be
methods only, but I can't find a reason why not, and a
search-on-wikipedia-instead-of-doing-proper-research appears to allow
it: http://en.wikipedia.org/wiki/Interface_%28computer_science%29

John.


-----Original Message-----
From: news [mailto:news@ger.gmane.org] On Behalf Of Sebastian Bergmann
Sent: 29 April 2008 11:16
To: internals@lists.php.net
Subject: Re: [PHP-DEV] Class Properties in Interfaces?

John Carter -X (johncart - PolicyApp Ltd at Cisco) schrieb:
> could you explain why Interfaces can't have properties

  Because interfaces are implemented which makes no sense for
attributes.

-- 
Sebastian Bergmann
http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B
5D69


--
 To unsubscribe,
visit: http://www.php.net/unsub.php

---

## #37295 — Nathan Nobbe — 2008-04-29T15:17:15+00:00

URL: https://externals.io/message/37281#37295 · In reply to: #37291

On Tue, Apr 29, 2008 at 6:28 AM, John Carter -X (johncart - PolicyApp Ltd at
Cisco) <johncart@cisco.com> wrote:

>
> I think I must be missing something here, but this sounds a little
> tautological - "we can't do it because it doesn't make sense. This is
> because it doesn't make sense"
>
> Certainly most people (myself included) consider interfaces to be
> methods only, but I can't find a reason why not, and a
> search-on-wikipedia-instead-of-doing-proper-research appears to allow
> it: http://en.wikipedia.org/wiki/Interface_%28computer_science%29


the problem with that article, as it pertains to this conversation is that
it is referring to interfaces as a general concept.  'interfaces' can be
formed in many ways, via extension of an abstract class or even an expected
set of a parameters in an HTTP request...
getting to the more concrete term 'interface' as it pertains to a language
keyword, interfaces define a contract; they do not specify implementation
details.  member variables only facilitate the actions member functions
expose and therefore, they are part of the implementation.

additionally, one can look to java (and likely others) to see that public
attributes are not supported on interfaces. here is a definition from a
java5 cert book;
"When you create an interface, you're defining a contract for *what* a class
can do, without saying anything about how the class will do it.  An
interface is a contract."

-nathan

---

## #37296 — Jeff Moore — 2008-04-29T15:22:58+00:00

URL: https://externals.io/message/37281#37296 · In reply to: #37287

> John Carter -X (johncart - PolicyApp Ltd at Cisco) schrieb:
> > […]
>
> Because interfaces are implemented which makes no sense for  
> attributes.


Sebastian,

This is true for the data storage representation of a property.

But, when you add the possibility of getters and setters, a property  
becomes an abstraction.  It would make sense that an interface  
declares abstractly that a property will be available while leaving it  
up to a class to implement it.  Whether the implementation would be  
through a instance variable or through accessor methods is an  
implementation detail.  This is known as the uniform access principle.

http://en.wikipedia.org/wiki/Uniform_access_principle

However, right now, we only have the virtual or "missing property"  
technique of defining accessors with __get and __set, rather than a  
structural syntax that could be used to verify interface  
implementations.  (The structural way could also offer better  
reflection, better performance, differing visibility for getters and  
setters, etc.)

Properties in interfaces make no sense now, but if we ever get a  
structural method of declaring getters and setters, they might make  
sense.

Best Regards,

Jeff

---

## #37303 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T15:51:30+00:00

URL: https://externals.io/message/37281#37303 · In reply to: #37295

The article explicitly mentions OOP interfaces in a few languages. But
the article, or for that matter any formal definition of an interface
isn't really what I asked about:
 
My question was simply: why can't interfaces have properties?
 
John.

---

## #37308 — Nathan Nobbe — 2008-04-29T16:14:10+00:00

URL: https://externals.io/message/37281#37308 · In reply to: #37303

On Tue, Apr 29, 2008 at 9:51 AM, John Carter -X (johncart - PolicyApp Ltd at
Cisco) <johncart@cisco.com> wrote:

> The article explicitly mentions OOP interfaces in a few languages.


my bad.


> But
> the article, or for that matter any formal definition of an interface
> isn't really what I asked about:
>
> My question was simply: why can't interfaces have properties?


when you say properties, do you mean a particular set of methods map to a
particular instance variable, as getters and setters (i saw that definition
from Sebastian earlier)?  if thats the case than interfaces cant have
properties because they require instance variables.

-nathan

---

## #37309 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T16:28:59+00:00

URL: https://externals.io/message/37281#37309 · In reply to: #37308

Nathan,
 
By example:
 
interface EggLayer
 
{
    public $eggsLaid;
}
 
class Chicken implements EggLayer;
 
Some would say (and maybe I would too) that you should have a
getEggsLaid() method, that's fair enough. But why not the above?
 
You say interfaces can't have properties because they require instance
variables. Why do they require instance variables? I also think for the
purposes of this discussion, property and instance variable mean the
same thing.
 
John.

---

## #37310 — Stanislav Malyshev — 2008-04-29T17:22:51+00:00

URL: https://externals.io/message/37281#37310 · In reply to: #37286

Hi!

> I understand why Interfaces can't have bodies, but could you explain why
> Interfaces can't have properties? 

Interfaces are API descriptions. API is usually seen as composed of 
functions. Some go even as far as recommending even classes don't have 
public properties at all :)

In any case, whenever you want to write $foo->bar, just write 
$foo->getBar() and $foo->setBar(), and it'd work :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37311 — Stanislav Malyshev — 2008-04-29T17:27:01+00:00

URL: https://externals.io/message/37281#37311 · In reply to: #37296

Hi!

> But, when you add the possibility of getters and setters, a property 
> becomes an abstraction.  It would make sense that an interface declares 

Nothing prevents you from having getters and setters as part of the 
interface :)

> Properties in interfaces make no sense now, but if we ever get a 
> structural method of declaring getters and setters, they might make sense.

You can easily have it right now:

function __get($name) {
$name = "__get".ucfirst($name);
return $this->$name();
}

etc.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37312 — Nathan Nobbe — 2008-04-29T17:29:54+00:00

URL: https://externals.io/message/37281#37312 · In reply to: #37309

On Tue, Apr 29, 2008 at 10:28 AM, John Carter -X (johncart - PolicyApp Ltd
at Cisco) <johncart@cisco.com> wrote:

> Nathan,
>
> By example:
>
> interface EggLayer
>
> {
>    public $eggsLaid;
> }
>
> class Chicken implements EggLayer;
>
> Some would say (and maybe I would too) that you should have a
> getEggsLaid() method, that's fair enough. But why not the above?


because, from above, $eggsLaid constitutes the implementation of any class
that implements EggLayer.

You say interfaces can't have properties because they require instance
> variables.


thats fine, in fact thats what i take the two terms to mean; however, there
was an alternate definition given in an earlier post and i just wanted to
clarify whether you were referring to that definition of property.  hence
forth i understand that you are not referring to that definition.


> Why do they require instance variables?


this was only based on the aforementioned definition of properties whereby a
property is an instance variable that has respective getters and setters.
in the absence of that definition, my statement is irrelevant.


> I also think for the
> purposes of this discussion, property and instance variable mean the
> same thing.


cool, then i would say that interfaces cannot have public properties in them
because it imposes implementation requirements on any implementors.  to
specify implementation details, there is the abstract class.

-nathan

---

## #37313 — John Carter -X johncart - PolicyApp Ltd@Cisco — 2008-04-29T18:04:30+00:00

URL: https://externals.io/message/37281#37313 · In reply to: #37311

I think there's been two responses to this query:

1. We can't have properties in interfaces because interfaces don't have
properties. I would say this is tautological and doesn't add anything.

2. Why would you need to? Getters and setters work.

So I suppose to answer my question for myself, there's no real technical
reason for not having properties in interfaces, but getters and setters
work just fine and no-one (including me) really misses them.

John.

---

## #37365 — Lars Strojny — 2008-04-29T18:33:21+00:00

URL: https://externals.io/message/37281#37365 · In reply to: #37310

Hi Stas, hi everbody,

Am Dienstag, den 29.04.2008, 10:22 -0700 schrieb Stanislav Malyshev:
[...]
> In any case, whenever you want to write $foo->bar, just write 
> $foo->getBar() and $foo->setBar(), and it'd work :)

I think the issue is, that PHP does not have defined properties with
attached validation (yes, I know about __get()/__set()). Now we just
have plain properties that may contain everything. If we would have
something like this:

class Clazz
{
   public $property
   {
       function get()
       {
           return $this->property;
       }
       function set($property)
       {
           $this->property = (int)$property;
       }
   }
}

In this case it, maybe it would make sense to allow definitions of
properties in interfaces. For example the following could require a
property to be read only:

class Clazz
{
    public $property
    {
        function get();
    }
}

An interface defines a halfway strict API. Allowing the current
properties in interfaces would not add any sensible functionality
because it would not define the API better.

cu, Lars

---

## #37316 — Robert Cummings — 2008-04-29T23:48:34+00:00

URL: https://externals.io/message/37281#37316 · In reply to: #37313

On Tue, 2008-04-29 at 20:04 +0200, John Carter -X (johncart - PolicyApp
Ltd at Cisco) wrote:
> I think there's been two responses to this query:
> 
> 1. We can't have properties in interfaces because interfaces don't have
> properties. I would say this is tautological and doesn't add anything.
> 
> 2. Why would you need to? Getters and setters work.
> 
> So I suppose to answer my question for myself, there's no real technical
> reason for not having properties in interfaces, but getters and setters
> work just fine and no-one (including me) really misses them.

I have to agree. Enforcing existence of a property is just as much part
of an interface as enforcing the existence of a method. Why go down the
clutzy getter and setter method route when properties were meant to be
accessed. Why should code be made slower? Methods are at least an order
of magnitude slower than direct property access.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP

---

## #37317 — Jeremy Privett — 2008-04-30T00:10:14+00:00

URL: https://externals.io/message/37281#37317 · In reply to: #37316

Robert Cummings wrote:
> On Tue, 2008-04-29 at 20:04 +0200, John Carter -X (johncart - PolicyApp
> Ltd at Cisco) wrote:
>   
> > […]
>
> I have to agree. Enforcing existence of a property is just as much part
> of an interface as enforcing the existence of a method. Why go down the
> clutzy getter and setter method route when properties were meant to be
> accessed. Why should code be made slower? Methods are at least an order
> of magnitude slower than direct property access.
>
> Cheers,
> Rob.
>   

I'm glad someone out there agrees with me.

-- 
Jeremy Privett
C.E.O. & C.S.A.
Omega Vortex Corporation

http://www.omegavortex.net

Please note: This message has been sent with information that could be confidential and meant only for the intended recipient. If you are not the intended recipient, please delete all copies and inform us of the error as soon as possible. Thank you for your cooperation.

---

## #37318 — Richard Quadling — 2008-04-30T00:14:21+00:00

URL: https://externals.io/message/37281#37318 · In reply to: #37316

2008/4/30 Robert Cummings <robert@interjinn.com>:
>
>  On Tue, 2008-04-29 at 20:04 +0200, John Carter -X (johncart - PolicyApp
>
> Ltd at Cisco) wrote:
> > […]
>
>  I have to agree. Enforcing existence of a property is just as much part
>  of an interface as enforcing the existence of a method. Why go down the
>  clutzy getter and setter method route when properties were meant to be
>  accessed. Why should code be made slower? Methods are at least an order
>  of magnitude slower than direct property access.
>
>  Cheers,
>  Rob.
>  --
>  http://www.interjinn.com
>  Application and Templating Framework for PHP

There are some advantages.

1 - Read only / write only properties can be created more obviously,
rather than having the logic spread thoughout the __magic_functions.
2 - Automatic document tools get a real benefit from having a defined
mechanism to work from.

Using a simple shape class, it is a toss up between $shape->getArea()
vs $shape->area

If PHP supported setters/getters in this way, then the interface for a
shape would have a fCalcArea member function requirement. You may want
to have the area updated upon the change of any of the dimensions.

Ideally the interface should also have a read only property of area,
but the support of properties in an interface is disputed here. In
this limited example, it would seem useful.

Richard.

-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

---

## #37319 — Nathan Nobbe — 2008-04-30T01:01:13+00:00

URL: https://externals.io/message/37281#37319 · In reply to: #37318

On Tue, Apr 29, 2008 at 6:14 PM, Richard Quadling <rquadling@googlemail.com>
wrote:

> 2008/4/30 Robert Cummings <robert@interjinn.com>:
> > […]
> have
> > […]
> technical
> > […]
> setters
> > […]
>
> There are some advantages.
>
> 1 - Read only / write only properties can be created more obviously,
> rather than having the logic spread thoughout the __magic_functions.
> 2 - Automatic document tools get a real benefit from having a defined
> mechanism to work from.
>

not only that, but the only recourse to add logic to access of previously
declared public variables without changing the interface is to resort to
magic methods.  up front, using public member variables may be enticing,
there are less instance methods and access is faster, sure.  but when, down
the road, some logic is required around access, and the only recourse is to
employ a magic method, what would be slower then?  the magic method doing
runtime introspection on the class instance prior to invoking said logic, or
having a purpose built method(s) there in the first place?  obviously the
later; and that is just one more reason why getters and setters, coupled
with hidden member variables, make sense, even in php.

-nathan

---

## #37320 — Robert Cummings — 2008-04-30T01:22:29+00:00

URL: https://externals.io/message/37281#37320 · In reply to: #37319

> On Tue, Apr 29, 2008 at 6:14 PM, Richard Quadling <rquadling@googlemail.com>
> wrote:
> 
> > […]
> 
> not only that, but the only recourse to add logic to access of previously
> declared public variables without changing the interface is to resort to
> magic methods.  up front, using public member variables may be enticing,
> there are less instance methods and access is faster, sure.  but when, down
> the road, some logic is required around access, and the only recourse is to
> employ a magic method, what would be slower then?  the magic method doing
> runtime introspection on the class instance prior to invoking said logic, or
> having a purpose built method(s) there in the first place?  obviously the
> later; and that is just one more reason why getters and setters, coupled
> with hidden member variables, make sense, even in php.

That should be a matter of choice for the developer. When you say "but
when, down the road, some logic...", all I see is you waving your hands
in the air and presuming that the logic will change. The logic may not
change, in which case why am I incurring the cost of getter/setter
methods. "If" the logic changes, I'll be happy to add getter and setter
methods at that time and punt the needed functionality into the magic
methods which will call the appropriate getter or setter method. You are
preparing for a future that may not come, I am willing to retroactively
handle that future "if" it arrives. Neither approach strikes me as being
more correct but rather they each presume an educated guess on the
likelihood of the property changing it's semantics down the road.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP

---

## #37322 — Nathan Nobbe — 2008-04-30T03:51:41+00:00

URL: https://externals.io/message/37281#37322 · In reply to: #37320

On Tue, Apr 29, 2008 at 9:22 PM, Robert Cummings <robert@interjinn.com>
wrote:

>
> 
> > […]
> rquadling@googlemail.com>
> > […]
> PolicyApp
> > […]
> anything.
> > […]
> part
> > […]
> the
> > […]
> be
> > […]
> order
> > […]
> down
> > […]
> to
> > […]
> or
> > […]
>
> That should be a matter of choice for the developer. When you say "but
> when, down the road, some logic...", all I see is you waving your hands
> in the air and presuming that the logic will change. The logic may not
> change, in which case why am I incurring the cost of getter/setter
> methods. "If" the logic changes, I'll be happy to add getter and setter
> methods at that time and punt the needed functionality into the magic
> methods which will call the appropriate getter or setter method. You are
> preparing for a future that may not come, I am willing to retroactively
> handle that future "if" it arrives. Neither approach strikes me as being
> more correct but rather they each presume an educated guess on the
> likelihood of the property changing it's semantics down the road.


the developer does have a choice.  to use an interface, or an abstract
class.  data facilitates methods accomplishing what it is they purport.
quite frankly, i have never written an interface with getters and / or
setters anyway, nor do i see the need to.  i would consider it silly.
interfaces are typically used to say, any class that makes this happen will
likely do it in a way differently than all the others.  since, getters and
setters are almost always implemented the exact same way i find these topics
to be rather different.  if there is in fact a standard way of doing things
for any given interface, then to realize it, a common implementor class can
be composed, and delegated to by classes that implement said interface in
the 'standard' way.

-nathan

---

## #37323 — Robert Cummings — 2008-04-30T04:05:38+00:00

URL: https://externals.io/message/37281#37323 · In reply to: #37322

> On Tue, Apr 29, 2008 at 9:22 PM, Robert Cummings <robert@interjinn.com>
> wrote:
> 
> > […]
> "but
> > […]
> hands
> > […]
> not
> > […]
> setter
> > […]
> magic
> > […]
> are
> > […]
> retroactively
> > […]
> being
> > […]
> 
> 
> the developer does have a choice.  to use an interface, or an abstract
> class.  data facilitates methods accomplishing what it is they
> purport.
> quite frankly, i have never written an interface with getters and / or
> setters anyway, nor do i see the need to.  i would consider it silly.
> interfaces are typically used to say, any class that makes this happen
> will
> likely do it in a way differently than all the others.  since, getters
> and
> setters are almost always implemented the exact same way i find these
> topics
> to be rather different.  if there is in fact a standard way of doing
> things
> for any given interface, then to realize it, a common implementor
> class can
> be composed, and delegated to by classes that implement said interface
> in
> the 'standard' way.

Abstract classes and interfaces are not the same. They are used for
fundamentally different reasons. An interface is to enforce a contract
for all implementations of the interface. Therefore if I were to create
an interface with an interface property of x, then all implementations
using that interface would know that property x exists and could use it
thusly without having to check for it's existence. Using an abstract
class is a hack, it's not sufficient for enforcement, and you can't
combine multiple abstract classes as you can with interfaces.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP

---

Next page: https://externals.io/message/37281.md?page=2
