Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
finalxcode
Design-Patterns
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Design-Patterns
/
User.php
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
30 lines (25 loc) · 1.32 KB
master
Breadcrumbs
Design-Patterns
/
User.php
Copy path
Top
File metadata and controls
Code
Blame
30 lines (25 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
namespace DesignPatterns;
class User
{
public $userId;
public $userName;
public $email;
public $telephone;
public $provinceOfAddress;//省
public $cityOfAddress;//市
public $regionOfAddress;//区
public $detailedAddress;//详细地址
}
//这个类是否满足职责单一呢?
//一种观点,认为user类中包含的都是跟用户相关的信息,属性都是这个业务模型的,满足单一职责
//另一种观点,认为地址信息在user类中占的比重大,可以拆分成userAddress类,
//user类保留除地址信息之外的其他信息,这样职责才单一。
//如果用户的信息还跟物流信息挂钩,那么按照第二种观点拆分的才更加合理。
//从这个例子上可以看出来,评价一个类是否职责单一,
//都是在某些场景下或者未来的某个需求下。我们并没有⼀个⾮常明确的、可以量化的标准,
//可以说,这是件⾮常主观、仁者⻅仁智者⻅智的事情。
//实际上,我们也没必要过于未⾬绸缪,过度设计。
//我们可以先写⼀个粗粒度的类,满⾜业务需求。
//随着业务的发展,如果粗粒度的类越来越庞⼤,代码越来越多,
//这个时候,我们就可以将这个粗粒度的类,拆分成⼏个更细粒度的类。进行所谓的重构。
You can’t perform that action at this time.