super() in injected methods

Alan Gauld alan.gauld at yahoo.co.uk
Fri Feb 12 04:35:39 EST 2021


On 12/02/2021 02:39, Andras Tantos wrote:

> 1. Ports, which are the connection points on the various netlist 
> entities. These would be the inputs and outputs of an AND gate for example
> 
> 2. NetTypes, which describe the type of data that can travel through a 
> net (and thus through a Port). One such type would be an 8-bit signed 
> integer, or a simple logic signal.

> 2. A (derived) Port instance has a member of a (derived) NetType instance

Sounds like the right solution.

> Now, when a Port gets assigned a NetType, it needs to gain all sorts of 
> new features. It for example should have a 'length' attribute that tells 
> how many bits are needed to represent its possible values. The list of 
> these new features (attributes, methods, properties) are known to the 
> NetType and should be injected into the Port when the NetType is 
> assigned to the Port.

So aren't these operations of the type rather than the port.
If you expose the type the users can message it directly.

n = myport.type.length()

Keep the responsibility with the object that owns them.
Creating a facade over another object is sometimes useful
but a dynamic facade sounds like trouble. Client code is
going to have to know which methods exist and when.
Can you ever change the type? What happens to the injected
methods, do you need to remove them and replace them
with others?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Python-list mailing list