mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-09-15 08:19:12 +00:00
fix: website build failed
This commit is contained in:
@@ -33,10 +33,6 @@ Wikipedia says
|
|||||||
|
|
||||||
> In object-oriented and functional programming, an immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created.
|
> In object-oriented and functional programming, an immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created.
|
||||||
|
|
||||||
Class diagram
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Programmatic Example of Immutable Pattern in Java
|
## Programmatic Example of Immutable Pattern in Java
|
||||||
|
|
||||||
The core of the pattern is `ImmutableUser`. All fields are `final`, the mutable `roles` list is defensively copied via `List.copyOf`, and "mutation" is expressed by returning a new instance.
|
The core of the pattern is `ImmutableUser`. All fields are `final`, the mutable `roles` list is defensively copied via `List.copyOf`, and "mutation" is expressed by returning a new instance.
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.immutable {
|
|
||||||
class App {
|
|
||||||
- LOGGER : Logger {static}
|
|
||||||
+ App()
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
}
|
|
||||||
class ImmutableUser {
|
|
||||||
- name : String {final}
|
|
||||||
- age : int {final}
|
|
||||||
- roles : List<String> {final}
|
|
||||||
+ ImmutableUser(name : String, age : int, roles : List<String>)
|
|
||||||
+ getName() : String
|
|
||||||
+ getAge() : int
|
|
||||||
+ getRoles() : List<String>
|
|
||||||
+ withAge(newAge : int) : ImmutableUser
|
|
||||||
+ toString() : String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
App ..> ImmutableUser : creates
|
|
||||||
@enduml
|
|
||||||
Reference in New Issue
Block a user