dart - Use getter and setter -


is recommended use in dart getter , setter define property like:

class car {   engine engine;    bool isenginerunning => engine.isrunning;    void set isenginerunning(bool isrunning) {     engine.isrunning = isrunning;   } } 

and advantage of it?

only if it's required because want execute additional code except forwarding field.

if getters , setters used wrap field, getters/setters explicitly discouraged because redundant.

in case, because not forwarding field _isenginerunning it's fine if don't want expose engine engine.

however because engine public might noise , confusing because same thing can done in 2 different ways.

if engine private better considering https://en.wikipedia.org/wiki/law_of_demeter


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -