tailieunhanh - Thinking in C# phần 5

. NET cho các chương trình Các hình thức của Windows, nó sẽ đặt tất cả các mã liên quan đến xây dựng những người sử dụng, giao diện vào một phương pháp được gọi là InitializeComponent (); phương pháp này có thể hàng trăm hàng dài, nhưng nó chứa không có kiểm soát, dòng chảy các nhà khai thác, vì vậy đó là chiều dàikhông thích hợp. Mặt khác, 15 dòng này tính năm nhuận khoảng phức tạp như là chấp nhận đượ. | .NET to program Windows Forms it will place all the code relating to constructing the user-interface into a method called InitializeComponent this method may be hundreds of lines long but it contains no control-flow operators so it s length is irrelevant. On the other hand the 15 lines of this leap year calculation are about as complex as is acceptable c09 using System class LeapYearCalc static bool LeapYear int year if year 4 0 return false else if year 400 0 return true else if year 100 0 return false else return true public static void Test int year bool val if val LeapYear year 0 correctly calced as 1 year val return throw new TestFailedException 0 not calc ed as 1 year val public static void Main Test 1999 false Test 2000 true Test 1900 false 342 Thinking in C class TestFailedException ApplicationException public TestFailedException String s base s Some simple testing code is shown because less than a month before this book went to press we found a bug in the LeapYearCalc function had So maybe the 15 lines in that function are a little more complex than allowable. Make stuff as private as possible Now that we ve introduced the concept of coupling and cohesion the use of the visibility modifiers in C should be more compelling. The more visible a piece of data the more available it is to be used for common coupling or communicational and worse forms of cohesion. The very real advantages that come from object-orientation C and the .NET Framework do not derive from the form of method calls or from using brackets to specify scope. The success of the object-oriented paradigm stems from encapsulation the logical organization of data and behavior with restricted access. Coupling and cohesion are more precise terms to discuss the benefits of encapsulation but class interfaces inheritance the visibility modifiers and Properties - the purpose of all of these things is to hide a large number of .

TỪ KHÓA LIÊN QUAN