-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Classes should interact through public APIs, not by reaching into each other's private attributes.
Example from MIKE IO plotting refactor:
Before (inappropriate intimacy):
# Plotter reaches into geometry internals for subsetting
values = values[self.da.geometry.top_elements]
geometry = self.da.geometry.geometry2d
# Plotter uses private attribute to check for time axis
if self.da._has_time_axis:
return self.da.values[0]After (using public API):
# Use sel/isel for subsetting
da = da.sel(layers="top")
geometry = da.geometry
# Use public dims property
da = self.da.isel(time=0) if "time" in self.da.dims else self.daKey principles:
- Never access private attributes (prefixed with
_) of another class - Use public methods like
sel,isel, and public properties likedims - If you need to access private state, that's a signal the class is missing a public API
- Plotters should plot, not subset — keep data manipulation in the data layer
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels