📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Table of contents |
---|
Problem |
Forces |
Solution |
Structure - Class Diagram, Sequence Diagram |
Participants and Responsibilities |
Implementation |
Consequences |
Applicability |
References |
Problem
Forces
- You want to encapsulate business logic in a centralized manner and prevent implementing it in the client.
- You want to minimize the network calls to remote objects when building a data representation of the business-tier object model.
- You want to create a complex model to hand over to the client for presentation purposes.
- You want the clients to be independent of the complexity of model implementation, and you want to reduce coupling between the client and the business components.
Solution
Structure
Class diagram
Sequence Diagram
Participants and Responsibilities
Implementation
- Project information from the Project component
- Project manager information from the ProjectManager component
- List of project tasks from the Project component
- Resource information from the Resource component.
public class ProjectDetailsData {
private ProjectTO projectData;
private ProjectManagerTO projectManagerData;
private Collection < TaskResourceTO > listOfTasks;
public ProjectDetailsData(ProjectTO projectData, ProjectManagerTO projectManagerData,
Collection < TaskResourceTO > listOfTasks) {
super();
this.projectData = projectData;
this.projectManagerData = projectManagerData;
this.listOfTasks = listOfTasks;
}
}
public class ResourceTO {
private String resourceId;
private String resourceName;
private String resourceEmail;
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public String getResourceEmail() {
return resourceEmail;
}
public void setResourceEmail(String resourceEmail) {
this.resourceEmail = resourceEmail;
}
}
public class TaskTO {
private String projectId;
private String taskId;
private String name;
private String description;
private Date startDate;
private Date endDate;
private String assignedResourceId;
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getAssignedResourceId() {
return assignedResourceId;
}
public void setAssignedResourceId(String assignedResourceId) {
this.assignedResourceId = assignedResourceId;
}
}
public class TaskResourceTO {
private String projectId;
private String taskId;
private String name;
private String description;
private Date startDate;
private Date endDate;
private TaskResourceTO assignedResource;
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public TaskResourceTO getAssignedResource() {
return assignedResource;
}
public void setAssignedResource(TaskResourceTO assignedResource) {
this.assignedResource = assignedResource;
}
}
public class ProjectManagerTO {
private String name;
private String address;
private String projects;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getProjects() {
return projects;
}
public void setProjects(String projects) {
this.projects = projects;
}
}
public class ProjectTO {
private String projectId;
private String projectName;
private String projectDesc;
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getProjectDesc() {
return projectDesc;
}
public void setProjectDesc(String projectDesc) {
this.projectDesc = projectDesc;
}
}
public class ProjectDetailsAssembler {
public ProjectDetailsData getData(String projectId) {
// Construct the composite transfer object
// get project related information from database and set to ProjectDetailsData class object.
ProjectTO projectData = new ProjectTO();
// get ProjectManager info and add to ProjectDetailsData
ProjectManagerTO projectManagerData = new ProjectManagerTO();
// construct a new TaskResourceTO using Task and Resource data.
//get the Resource details from database.
// construct a list of TaskResourceTOs
Collection < TaskResourceTO > listOfTasks = new ArrayList < > ();
// Add Project Info to ProjectDetailsData
// Add ProjectManager info to ProjectDetailsData
ProjectDetailsData pData = new ProjectDetailsData(projectData, projectManagerData, listOfTasks);
return pData;
}
}
Consequences
- Separates business logic, simplifies client logic
- Reduces coupling between clients and the application model
- Improves network performance
- Improves client performance
- Can introduce stale data
Comments
Post a Comment
Leave Comment