-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputer.cpp
More file actions
58 lines (54 loc) · 1.65 KB
/
Copy pathcomputer.cpp
File metadata and controls
58 lines (54 loc) · 1.65 KB
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
#include "computer.h"
#include <sstream>
std::string Computer::describe() const {
std::ostringstream oss;
oss << "CPU=" << cpu_ << ", 内存=" << ram_
<< ", 存储=" << storage_ << ", 显卡=" << gpu_;
return oss.str();
}
ComputerBuilder& GamingComputerBuilder::build_cpu() {
computer_->set_cpu("Intel Core i9-14900K");
return *this;
}
ComputerBuilder& GamingComputerBuilder::build_ram() {
computer_->set_ram("32GB DDR5");
return *this;
}
ComputerBuilder& GamingComputerBuilder::build_storage() {
computer_->set_storage("2TB NVMe SSD");
return *this;
}
ComputerBuilder& GamingComputerBuilder::build_gpu() {
computer_->set_gpu("NVIDIA RTX 4090");
return *this;
}
std::unique_ptr<Computer> GamingComputerBuilder::result() {
auto built = std::move(computer_);
computer_ = std::make_unique<Computer>();
return built;
}
ComputerBuilder& OfficeComputerBuilder::build_cpu() {
computer_->set_cpu("Intel Core i5-13400");
return *this;
}
ComputerBuilder& OfficeComputerBuilder::build_ram() {
computer_->set_ram("16GB DDR4");
return *this;
}
ComputerBuilder& OfficeComputerBuilder::build_storage() {
computer_->set_storage("512GB SSD");
return *this;
}
ComputerBuilder& OfficeComputerBuilder::build_gpu() {
// 办公场景无需独立显卡,保持默认集成显卡
return *this;
}
std::unique_ptr<Computer> OfficeComputerBuilder::result() {
auto built = std::move(computer_);
computer_ = std::make_unique<Computer>();
return built;
}
std::unique_ptr<Computer> Director::construct() {
builder_.build_cpu().build_ram().build_storage().build_gpu();
return builder_.result();
}