C#/VB.NET 物件導向技巧研究(一)_Chain Constructors_optional parameters
C# /VB.NET 建構子設計中常遇到的 冗長設計 問題 如下我們建立一個摩托車的類別來詳述一些 還能再改善的程式碼片段徵兆 Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 class Motorcycle { public int driverIntensity; public string driverName; //driver name public int driverYear; // driver year public void SetDriverName ( string name) { this .driverName = name; } public void SetDriverYear ( int year) { driverYear = year; } public Motorcycle (){} //冗長的建構子函數......................... //確保駕駛安全並限定強度等級不超出10 public Motorcycle ( int intensity) { if (intensity > 10 ) { intensity = 10 ; } driverIntensity = intensity; } public Motorcycle ( int intensity , string name) { if (...