Skip to content

Add proper getters and setters to all public attributes on objects #6

@elaguerta

Description

@elaguerta

Many objects have attributes that are not preceded by underscores, therefore by convention, they are considered to be public. It would be better practice to make all attributes private, and provide getters and setter methods for users to explicitly read and change attributes. Here is a general example of how to revise:

Before: attributes set on the object without getters/setters:

class Solution

  def __init__(dss_file, **kwargs):
    self.V = None

After: prepend all attributes with underscores and provide getters and setters as appropriate:

class Solution

  def __init__(dss_file, **kwargs):
    self._V = None

  def get_V(self):
    return self._V

  def set_V(self):
    raise Error("Cannot set Solution voltages.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions