How to make this facility more convenient for maintenance?

For example, I have something like this:

User
-FirstName
-SecondName
-Gender

and VIPUserwhich is a subclassUser

VIPUser extends User
-GiftNum
-Birthday

But suddenly, the application must change the policy, everyone Usershould have Birthday.... And this is not an optional field that no longer allows you nullto set for the user, it becomes MUST fills the variable for the new register User, but I can stay nullfor the existing user ...

So, I will need to change the whole creation method Userand pass Birthday, it includes many codes. How can I make it more convenient for maintenance? Thank.

+3
source share
5 answers

?

, , , - , .

, ... ... , Java. , API- .


:

  • - . , , .

  • ( ) - , , . -, , . , , , codebase. " " , .

  • . IDE . , ... IDE.

+4

, , .

User ... , .

+3

, User, Date, Birthday, . , @NimChimpsky, ( -, ).

+1

API- , . - .

, .

API- , API . - .:)

Factory (pattern) . , , IDE .

+1

. Java-IDE, . , " ".

Refactoring is fairly simple (I prefer IntelliJ, but I think Eclipse and Netbeans will do a good job too).

0
source

All Articles