forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktop.java
82 lines (70 loc) · 2.6 KB
/
Desktop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.designpatterns.creational.builder;
/**
* The Builder is a design pattern designed to provide a flexible solution to various object creation problems in
* object-oriented programming. The intent of the Builder design pattern is to separate the construction of a complex
* object from its representation.
*
* @see <a href="https://en.wikipedia.org/wiki/Builder_pattern">Builder Pattern</a>
*/
public class Desktop {
private String CPU;
private String RAM;
private boolean isGraphicCardEnabled;
private String operatingSystem;
private int diskSizeGB;
private String graphicCard;
private Desktop(DesktopBuilder builder) {
this.CPU = builder.CPU;
this.RAM = builder.RAM;
this.isGraphicCardEnabled = builder.isGraphicCardEnabled;
this.operatingSystem = builder.operatingSystem;
this.diskSizeGB = builder.diskSizeGB;
this.graphicCard = builder.graphicCard;
}
/**
* Builder class for the above Desktop class. Constructs the Desktop by invoking the Desktop class constructor and
* allows access to set optional fields in the Desktop class.
*/
public static class DesktopBuilder {
private String CPU;
private String RAM;
private boolean isGraphicCardEnabled;
private String operatingSystem;
private int diskSizeGB;
private String graphicCard;
public DesktopBuilder(String CPU, String RAM) {
this.CPU = CPU;
this.RAM = RAM;
}
public DesktopBuilder setGraphicCardEnabled(boolean graphicCardEnabled) {
this.isGraphicCardEnabled = graphicCardEnabled;
return this;
}
public DesktopBuilder setOperatingSystem(String operatingSystem) {
this.operatingSystem = operatingSystem;
return this;
}
public DesktopBuilder setDiskSizeGB(int diskSize) {
this.diskSizeGB = diskSize;
return this;
}
public DesktopBuilder setGraphicCard(String graphicCard) {
this.graphicCard = graphicCard;
return this;
}
public Desktop build() {
return new Desktop(this);
}
}
@Override
public String toString() {
return "Desktop{" +
"CPU='" + CPU + '\'' +
", RAM='" + RAM + '\'' +
", isGraphicCardEnabled=" + isGraphicCardEnabled +
", operatingSystem='" + operatingSystem + '\'' +
", diskSizeGB=" + diskSizeGB +
", graphicCard='" + graphicCard + '\'' +
'}';
}
}