[Tutor] Class access rules

Phil phillor9 at gmail.com
Mon Mar 7 18:17:23 EST 2022


On 7/3/22 22:30, Alan Gauld via Tutor wrote:

> In good OOP design you should ideally not need to
> access the internal attributes of a class at all. The
> methods should do all the work and the attributes are only
> there internally to support those methods. In practice
> of course objects often represent data stores and the
> attributes are of interest. But the goal should be
> to minimize that and not to expose them.

I suppose I really should have said good practice rather that correctness.

My LED class uses a boolean state attribute, if the state is True then 
the LED is filled with the on_colour. I had in mind creating on and off 
methods that set the state rather then directly setting the state 
attribute. From what I understand setting the state attribute directly 
is good practice.

-- 

Regards,
Phil



More information about the Tutor mailing list