Req #75082 [Opn->Fbk]: Add interface for SplObjectStorage and use that instead bounding to the class

From: Date: Thu, 19 Oct 2017 21:40:37 +0000
Subject: Req #75082 [Opn->Fbk]: Add interface for SplObjectStorage and use that instead bounding to the class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211788@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75082&edit=1

 ID:                 75082
 Updated by:         nikic@php.net
 Reported by:        adaliszk at gmail dot com
 Summary:            Add interface for SplObjectStorage and use that
                     instead bounding to the class
-Status:             Open
+Status:             Feedback
 Type:               Feature/Change Request
 Package:            SPL related
 Operating System:   Irrelevant
 PHP Version:        7.1.8
 Block user comment: N
 Private report:     N

 New Comment:

This description is very confusing to me, because I don't understand how having an interface
for SplObjectStorage will help you with a ProductCollection based on SplObjectStorage. The
ProductCollection will still have to satisfy that interface, which is not possible if you restrict
the types of accepted objects and our LSP checks will prohibit it. Something akin to this is only
possible using generics. Am I misunderstand this request?


Previous Comments:
------------------------------------------------------------------------
[2017-08-17 08:02:32] adaliszk at gmail dot com

Description:
------------
So basically if I build my datastructures using SplObjectStorage logic I cannot define properly an
interface for my each collection and force usage of a subtype for each of the attach/detach and
add/remove methods.

For example I want to build a ProductCollection which expect working with only the same type when
adding and removing and also has a boundary to only accept ProductEntity I cannot define the
interface properly since the SplObjectStorage is bound to itself not to an interface.

Sure you can do it with abstract classes and define this boundaries but then each of your collection
abstractions would be separated from your other interfaces and you loose polymorphic dependencies or
you need to drop your architecture and care this differently.

This change should not provide any BC issues, since it's just add interface around the
ObjectStorage but it will allow polymorphic interfaces and more tools to design your architecture
without implementing code.




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=75082&edit=1


Thread (3 messages)

« previous php.bugs (#211788) next »