1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Using Design Patterns in Java Projects

Composite Entity

Contents

keyboard_tab
Design Patterns
1
Design Patterns
PREVIEW2m 26s
2
Singleton Pattern
PREVIEW3m 13s
9
Decorator
7m 48s
10
Flyweight
9m 20s
11
Proxy
7m 36s
12
Facade
6m 5s
14
Command
11m 44s
15
Iterator
8m 24s
16
Visitor
9m 4s
17
Mediator
11m 38s
18
Memento
9m 48s
19
Observer
10m 40s
20
Strategy
8m 27s
21
State
10m 27s
22
Template
7m 56s
23
MVC
10m 27s
26
DAO
10m 27s
27

The course is part of this learning path

Start course
Overview
Difficulty
Intermediate
Duration
4h 56m
Students
20
Ratings
5/5
starstarstarstarstar
Description

This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.

Learning Objectives

  • Understand what design patterns are
  • Learn about the myriad of design patterns that you can use in your projects

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.

Prerequisites

Basic knowledge of Java programming.

 

Transcript

Hello, dear friends. In this video, we will examine the Composite Entity Pattern. Let's begin. As described by GoF, CompositeEntity pattern compose objects into tree structure to represent part whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. In object-oriented programming, a composite is an object designed as a composition of one or more similar objects, all exhibiting similar functionality. This is known as a HAS-A relationship between objects. CompositeEntity is a Java EE software design pattern and it's used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine grain entity beans. And also, a CompositeEntity bean represents a graph of objects. Composite Entity pattern is used in EJB persistence mechanism. A CompositeEntity is an EJB entity bean which represents a graph of objects. When a CompositeEntity is updated internally DependentObject beans get updated automatically as being managed by EJB Entity Bean.

As you can see in the UML of CompositeEntity pattern, there are four participants. CompositeEntity is primary entity bean. It can be CoarseGrained or it can contain a CoarseGgrainedObject to be used for persistence purposes. CoarseGrainedObject contains DependentObjects. It has its own life cycle and also manages the lifecycle of DependentObjects. DependentObject is an object which depends on CoarseGrainedObject for its persistence lifecycle. Strategies represent how to implement a CompositeEntity. 

Now, as we have learned the structure of composite entity pattern, let's create a project and implement the pattern. Create a new project and name it CompositeEntity. I would like to use the employee example again. Let's define two classes which feature data that would need to update another class. First one is Employee. Define name and job state. Generate getter and setter for job state. Now, let's add a manager. In this, we will define name and satisfaction. If the employee does well, the manager is satisfied and vice versa. Generate getter and setter for satisfaction. Since the point of this pattern is not to allow the beans to act as FineGrainedObjects alone, we're introduced with  a CoarseGrainedObject. This object manages its own relationships to other objects. In CoarseGrainedObject class we will use employee and manager together. Let's define two methods to setData and getData.

Done. Now, we have to define a CompositeEntity class. This class is itself a CoarseGrainedObject and can reference another. First, define CoarseGrainedObject. Now, add getData and setData methods. And of course, we need a user as a client. Define CompositeEntity. Let's add a print method. Now, we will use setData also. We have a finished structure. Let's use. Now, we only need client. Define client instance. Now, setData. Print. Change, and print again. Now, let's look at the result. Run. Look, if employee is successful, manager is satisfied, else, manager is unsatisfied. With this video, we have finished examining the business tier patterns. In the next video, we will start to look at presentation tier patterns, starting with the intercepting filter pattern. See you in the next video.

 

About the Author
Students
413
Courses
35
Learning Paths
2

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics