Lý do là bạn có thể nhận thấy rằng có một lớp kế thừa từ nhiều lớp của cùng một mẫu, với các loại khác nhau liên kết với nó. Đây là một điều tốt vì nó cho phép bạn để cô lập các chức năng cụ thể vào các lớp riêng biệt. Một điều đáng chú ý là bạn có thể tạo ra một lớp templated | The cDate Class 31 Once upon a time there was a project being done at a very large company. A software audit showed at least five different routines functions macros and inline code that computed whether a given year was a leap year. This was pretty surprising but even more surprising was that of those five routines three were actually wrong. If a bug occurred while the system was calculating whether the current year was a leap year did the programmer have any idea where to look to solve the problem Of course not. In this example despite the risk of bugs you still have to determine whether a given date is valid and whether the given year is a leap year. Your first two basic tasks are to set appropriate defaults for the date and make sure you can retrieve all the components of the date. The same approach works for any business-rule encapsulation. First you have to know the pieces of the puzzle that go into the calculations. That way anyone looking at the code will know exactly what he or she needs to supply. There should be no hidden data unless it s being retrieved from an external source. The code should be plug-and-play you should be able to take it from one project to another with minimal changes. Of course it s often impossible to completely remove application code from business rules. But that really shouldn t be your goal when you re writing business objects. Instead you should worry about how those objects are going to be used. When you separate the support code from the te- business rule that it supports you separate the bugs that can occur into two types physical errors and logical errors. This alone saves time in tracking down problems. A logical error won t crash a program but it will cause grief in other ways. A physical error isn t likely to cause you to incorrectly generate checks for billions but it will crash your application and annoy your users. Your object should be portable it is going to be used in multiple projects to support the date rule. .