mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 08:18:23 +00:00
docs: update value object
This commit is contained in:
1 parent
723b1bf311
commit
5d44152bbc
1 file changed
+11
-10
+11
-10
@@ -51,7 +51,6 @@ Here is the `HeroStat` class that is the value object. Notice the use of [Lombok
|
|||||||
@Value(staticConstructor = "valueOf")
|
@Value(staticConstructor = "valueOf")
|
||||||
@ToString
|
@ToString
|
||||||
class HeroStat {
|
class HeroStat {
|
||||||
|
|
||||||
int strength;
|
int strength;
|
||||||
int intelligence;
|
int intelligence;
|
||||||
int luck;
|
int luck;
|
||||||
@@ -61,16 +60,18 @@ class HeroStat {
|
|||||||
The example creates three different `HeroStat`s and compares their equality.
|
The example creates three different `HeroStat`s and compares their equality.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
var statA = HeroStat.valueOf(10, 5, 0);
|
public static void main(String[] args) {
|
||||||
var statB = HeroStat.valueOf(10, 5, 0);
|
var statA = HeroStat.valueOf(10, 5, 0);
|
||||||
var statC = HeroStat.valueOf(5, 1, 8);
|
var statB = HeroStat.valueOf(10, 5, 0);
|
||||||
|
var statC = HeroStat.valueOf(5, 1, 8);
|
||||||
|
|
||||||
LOGGER.info("statA: {}", statA);
|
LOGGER.info("statA: {}", statA);
|
||||||
LOGGER.info("statB: {}", statB);
|
LOGGER.info("statB: {}", statB);
|
||||||
LOGGER.info("statC: {}", statC);
|
LOGGER.info("statC: {}", statC);
|
||||||
|
|
||||||
LOGGER.info("Are statA and statB equal? {}", statA.equals(statB));
|
LOGGER.info("Are statA and statB equal? {}", statA.equals(statB));
|
||||||
LOGGER.info("Are statA and statC equal? {}", statA.equals(statC));
|
LOGGER.info("Are statA and statC equal? {}", statA.equals(statC));
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's the console output.
|
Here's the console output.
|
||||||
@@ -137,4 +138,4 @@ Trade-offs:
|
|||||||
* [Effective Java](https://amzn.to/4cGk2Jz)
|
* [Effective Java](https://amzn.to/4cGk2Jz)
|
||||||
* [J2EE Design Patterns](https://amzn.to/4dpzgmx)
|
* [J2EE Design Patterns](https://amzn.to/4dpzgmx)
|
||||||
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
|
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
|
||||||
* [ValueObject - Martin Fowler](https://martinfowler.com/bliki/ValueObject.html)
|
* [ValueObject (Martin Fowler)](https://martinfowler.com/bliki/ValueObject.html)
|
||||||
Reference in new issue
Block a user