DHI / DHI/python-package-development

Add section on inappropriate intimacy between classes

未關閉
#35 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Jupyter Notebook
星號
8
分支
1
平均合併
4 分鐘
30 天內合併 PR
1

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

先找到課程文件中涵蓋類別設計或繪圖的章節,因為 issue 沒有指明檔案或進入點。在該處加入提供的說明和 MIKE IO 範例,保留關於公開 API 和資料操作的指引;當新章節發布於適當的課程教材中時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。