《K的技術學習筆記》——良好OOP的設計原則:<SOLID Principles>(一)

in #cn4 years ago

Slice 1.png
剛作為Programmer時, 我自己只在意一件事, 就是完成老闆要求的工作。在沒有良好的導師教導和只求快速完成feature下, 結果就是只為能做到而去做, 並沒有考慮程式的結構和可讀性等要素。這樣會在往後的擴展, 維護和別人合作時出現大問題。例如:加新feature很癈時間, 代碼難讀等。

在上一個工作環境, 就有一位上司提議我去看看——SOLID Principles。盡量跟隨這個Principles去設計程式, 就可以令程式更易擴展和維護。

什麼是SOLID Principles呢?

這個Principles有五個大原則, 他們分別是單一功能(Single responsibility principle),開閉原則(Open–closed principle),里氏替換(Liskov substitution principle),接口隔離(Interface segregation principle)和依賴轉換(Dependency inversion principle)。

單一功能(Single responsibility principle)

只因一個職責而去作改變

開閉原則(Open–closed principle)

完成後不作非必要的改動

里氏替換(Liskov substitution principle)

sub-class必須能夠替換其super-class

接口隔離(Interface segregation principle)

Client只依賴它所需要interface

依賴轉換(Dependency inversion principle)

用抽象觀念替代具體物件的關係

這也只是一個簡介。之後, 每一個原則都會寫一篇筆記去詳細解說, 並附上例子。暫時就先記錄這麼多。

Sort:  

Testing
突然出5到文?

Posted using Partiko iOS

Thank you for using @sleepagent bid bot serves.
This post has received a 33 % upvote from @sleepagent.

Thank you for using @sleepagent bid bot serves.
This post has received a 66 % upvote from @sleepagent.