Test driven development and The value object pattern

来源:互联网 发布:java飞机大战项目总结 编辑:程序博客网 时间:2024/05/17 03:12

Test driven development

With the value object pattern , First we should write a test file , and if use Zend Studio Editer we can generate test file from file | new | PHPUnit Test Case . Then the test file about four operations just like this:

 

 

 

 

Then based the test code above this is a class about four operations :

 

 

Finally , run the test file with click right | run as | PHPUnit Test to check whether there have some bug or not.

 

The value object pattern

Generally , There are three features in the value object pattern:

  • The property should be protected (will be defined with protected of private) , cann't be public;
  • The property should be assigned in the construct;
  • The property shouldn't be changed in any methods , if you want to chang it , you must build a new object which the property been set to new value.

 

Frist we still should make a test file :

 

 

Then this is the example about the value object pattern based on test file above:

 

 

 

 

 

原创粉丝点击