Last active
April 19, 2024 15:36
-
-
Save mcsee/87977580c06f4816c48ca9c6f9d10b23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreditCard { | |
private String number; | |
private MonthOfYear expiryDate; | |
// expiryDate is the role | |
// MonthOfYear is the type | |
} | |
class MonthOfYear { | |
private Month month; | |
private Year year; | |
// These are other small objects | |
public MonthOfYear(Month month, Year year) { | |
// You don't need to add validations since | |
// month is a valid month | |
// year is a valid year | |
this.month = month; | |
this.year = year; | |
} | |
public boolean isBeforeEndOfMonth(Date date) { | |
Calendar calendar = Calendar.getInstance(); | |
calendar.setTime(date); | |
return (calendar.get(Calendar.YEAR) < year.value()) || | |
(calendar.get(Calendar.YEAR) == year.value() && | |
calendar.get(Calendar.MONTH) < month.value()) | |
// Notice there are no days involved | |
} | |
// This protocol is just for MonthOfYears | |
public Day[] getDaysInMonth() { } | |
public boolean isLeapYear() { } // ... | |
public void iterateDays() { } // ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment