File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -172,3 +172,42 @@ of ``get_all``:
172172
173173 Consider changing ReadOnlyMapping.get_all or making these attributes part of ReadOnlyMapping.
174174 class ReadOnlyMapping(interface.Interface):
175+
176+ Interface Subclassing
177+ ~~~~~~~~~~~~~~~~~~~~~
178+
179+ Interfaces can inherit requirements from other interfaces via subclassing. For
180+ example, if we want to create interfaces for read-write and read-only mappings,
181+ we could do so as follows:
182+
183+ .. code-block :: python
184+
185+ class ReadOnlyMapping (interface .Interface ):
186+ def get (self , key ):
187+ pass
188+
189+ def keys (self ):
190+ pass
191+
192+
193+ class ReadWriteMapping (ReadOnlyMapping ):
194+
195+ def set (self , key , value ):
196+ pass
197+
198+ def delete (self , key ):
199+ pass
200+
201+
202+ An interface that subclasses from another interface inherits all the function
203+ signature requirements from its parent interface. In the example above, a class
204+ implementing ``ReadWriteMapping `` would have to implement ``get ``, ``keys ``,
205+ ``set ``, and ``delete ``.
206+
207+ .. warning ::
208+
209+ Subclassing from an interface is not the same as implementing an
210+ interface. Subclassing from an interface **creates a new interface ** that
211+ adds additional methods to the parent interface. Implementing an interface
212+ creates a new class whose method signatures must be compatible with the
213+ interface being implemented.
You can’t perform that action at this time.
0 commit comments