DHI / DHI/python-package-development

Add section on inappropriate intimacy between classes

Aperta
#35 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Jupyter Notebook
Stelle
8
Fork
1
Merge medio
4m
PR unite (30g)
1

Descrizione

Classes should interact through public APIs, not by reaching into each other's private attributes.

**Example from MIKE IO plotting refactor:**

Before (inappropriate intimacy):
```python
# 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):
```python
# 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.da
```

**Key principles:**
- Never access private attributes (prefixed with `_`) of another class
- Use public methods like `sel`, `isel`, and public properties like `dims`
- 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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start by locating the course documentation section covering class design or plotting, since the issue does not name a file or entry point. Add the provided explanation and MIKE IO examples there, preserving the guidance on public APIs and data manipulation; done means the new section is published in the appropriate course material.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.