Những thay đổi này đơn giản làm cho lớp Pos_Date nhiều hơn nữa mạnh mẽ hơn so với các lớp cha mẹ. Điều đó hoàn thành trọng các phương pháp di truyền. Tất cả các thay đổi sau đó thêm một phương thức mới để tăng cường chức năng của lớp. | Simpo PDF Merge and Split Unregistered Version - http PHP OBJECT-ORIENTED SOLUTIONS These simple changes make the Pos_Date class much more robust than the parent class. That completes overriding the inherited methods. All subsequent changes add new methods to enhance the class s functionality. You can either go ahead and implement all the new methods or just choose those that suit your needs. Let s start by adding some new ways to set the date. Accepting dates in common formats When handling dates in user input my instinct tells me not to trust anyone to use the right format so I create separate fields for year month and date. That way I m sure of getting the elements in the right order. However there are circumstances when using a commonly accepted format can be useful such as an intranet or when you know the date is coming from a reliable source like a database. I m going to create methods to handle the three most common formats MM DD YYYY American style DD MM YYYY European style and YYYY-MM-DD the ISO standard which is common in East Asia as well as being the only date format used by MySQL . These methods have been added purely as a convenience. When both the month and date elements are between 1 and 12 there is no way of telling whether they have been inputted in the correct order. The MM DD YYYY format interprets 04 01 2008 as April 1 2008 while the DD MM YYYY format treats it as January 4 2008. They all follow the same steps 1. Use the forward slash or other separator to split the input into an array. 2. Check that the array contains three elements. 3. Pass the elements date parts in the correct order to Pos_Date setDate . I pass the elements to the overridden setDate method rather than to the parent method because the overridden method continues the process like this 4. It checks that the date parts are numeric. 5. It checks the validity of the date. 6. If everything is OK it passes the date parts to the parent setDate method and resets the