Académique Documents
Professionnel Documents
Culture Documents
CT070-3-3-DPAT
a
Individual Assignment
Shopping Mall
Sree Prakash a/l Baskaran
| TP032890
Contents
Overview of the application .......................................................................................................................... 3
Description ................................................................................................................................................ 3
Assumptions.............................................................................................................................................. 3
System Architecture...................................................................................................................................... 4
Use Case Diagram ..................................................................................................................................... 4
Use Case Specifications ............................................................................................................................. 5
User Interface Documentation ................................................................................................................... 10
Design Patterns ........................................................................................................................................... 15
Abstract Factory with Factory Methods Pattern .................................................................................... 15
Factory Method Pattern ..................................................................................................................... 15
Abstract Factory Pattern ..................................................................................................................... 15
Singleton Pattern .................................................................................................................................... 19
Observer Pattern..................................................................................................................................... 21
Command ................................................................................................................................................ 23
Refined Class Diagram ................................................................................................................................ 26
Critical Appraisal ......................................................................................................................................... 27
Limitations of the application ................................................................................................................. 27
Future Enhancements ............................................................................................................................. 27
Challenges Faced..................................................................................................................................... 28
Design Pattern Suitability for implementing Object Oriented solutions ................................................ 29
Abstract Factory with Factory Methods Pattern ................................................................................ 29
Singleton Pattern ................................................................................................................................ 30
Observer Pattern................................................................................................................................. 30
Command Pattern ............................................................................................................................... 31
References .................................................................................................................................................. 32
Appendix ..................................................................................................................................................... 33
Assumptions
1. Only 3 stores exist in the mall.
2. Only 5 items exist in each mall.
3. Every store has a unique ID.
4. Every item has a unique ID; the name and price of the item can be the same.
5. Every customer has auto generated unique ID; the name of the customer can be the same.
6. Once an item is added into the store, it is never removed.
7. Quantity of each item is unlimited; customers can add many of the same item to their
shopping cart.
8. A customer will use the same shopping cart throughout their time in the shopping mall.
9. When a customer checks out of the store and purchases the items, the customer also
exits the store.
System Architecture
A system architecture is the conceptual model that defines the structure, behavior, and views of
a system. An architecture description is a formal description and representation of a system,
organized in a way that supports reasoning about the structures and behaviors of the system
(Architecture-Driven Modelling Methodologies, 2011).
The boundary, which defines the system of interest in relation to the world around it.
The actors, usually individuals involved with the system defined according to their roles.
The use cases, are the specific roles played by the actors within and around the system.
The relationships between and among the actors and the use cases.
Customer
View Store
For customers to view all the stores in the shopping mall.
Customer has to open the application and login.
Customer is logged in to the system and the stores are displayed.
1. Customer enters their name and logs in.
2. The stores in the shopping mall is displayed.
2. Customer logs in with an empty field for name.
2a. Error message is shown to customer.
-
Alternative path
Includes
Extends
Customer
Enter Store
For customers to enter store and view items in that store.
Customer must be logged in to the system.
Customer selects a store and views the items in that particular store.
1. Customer selects a store.
2. The items in the store is displayed.
View Items in Store
-
3) Exit Store
Actor
Use case name
Description
Precondition
Postcondition
Customer
Exit Store
For customers to exit the store.
Customer must have been in a store.
Customer has exited the store.
5
Main flow
Alternative path
Includes
Extends
Postcondition
Main flow
Alternative path
Includes
Extends
9) Checkout
Actor
Use case name
Description
Precondition
Postcondition
Main flow
Alternative path
Includes
Extends
Customer
Checkout
For customers to checkout and purchase their items.
There must be items in the shopping cart.
Customer is checked out from the store and the items are purchased.
1. The customers checks out from the store.
2. The price for the items is displayed.
3. Customer purchases the items.
Purchase Items
-
10
11
12
13
14
Design Patterns
The design patterns used in this application are Abstract Factory with Factory Methods,
Singleton, Observer, and Command.
You want to define the interface for creating a new object so that a service provider
decides which class to instantiate instead of clients.
You want to connect parallel hierarchies by letting subclasses in one hierarchy determine
which class to instantiate in the corresponding hierarchy.
15
You want to return one of several related classes of objects, each of which can return
several different objects on request.
The Abstract Factory pattern is one level of abstraction higher than the factory pattern. It is
basically a factory that creates factories.
For the shopping mall application, the researcher created all stores using factories. Below are
some screenshots:
Abstract Factory Pattern #1
16
17
18
Singleton Pattern
The Singleton patterns intent is to ensure that a class has only one instance, and to provide a
global point of access to it.
The Singleton pattern can be applied when:
There must be exactly one instance of a class, and it must be accessible to clients from a
well-known access point.
When the sole instance should be extensible by subclassing, and clients should be able to
use an extended instance without modifying their code.
For the shopping mall application, the researcher used the Singleton pattern in each store
factory to allow only one instance of any created factory type. Below are some screenshots:
Singleton Pattern #1
19
Singleton Pattern #2
Singleton Pattern #3
20
Observer Pattern
The Observer patterns intent is to define a one-to-many dependency between objects so that
when one object changes state, all its dependents are notified and updated automatically.
The Observer pattern can be applied when:
An abstraction has two aspects, one dependent on the other. Encapsulating these aspects
in separate objects let you vary and reuse them independently.
A change to one object requires changing others, and you dont know how many objects
need to be changed.
An object should be able to notify other objects without making assumption about who
these objects are. In other words, you dont want these objects tightly coupled.
In the shopping mall application, the observer pattern is used to notify registered customers
when a new item is added to a store. Below are some screenshots:
Observer Pattern #1
21
Observer Pattern #2
Observer Pattern #3
22
Command
The Command patterns intent is to encapsulate a request as an object, thereby letting you
parameterise clients with different requests, queue or log requests, and support undoable
operations.
The Command pattern can be applied when:
For the shopping mall application, the Command pattern is used to provide the customer with
the ability to undo a previous action. Below are some screenshots:
Command Pattern #1
23
Command Pattern #2
Command Pattern #3
24
Command Pattern #4
25
**It is important to note that the application and class diagram above differ. Therefore the classes here do not reflect the classes in
the application. This is the initial class diagram drawn up by the reseacher.
Critical Appraisal
Limitations of the application
The limitations of the application is as such:
1. The application is unable to add new stores.
2. The application is unable to remove stores.
3. The application is unable to edit current stores.
4. The application is unable to remove items.
5. The application is unable to edit items.
6. The application is not very user interactive.
7. The application takes up most of the screen size of a standard computer.
8. There isnt any layer of security.
9. No login and logout features.
10. There is essentially no store owner in this application, only customer and mall admin.
11. There is not helpful text to guide the user on how to use this application.
Future Enhancements
The future enhancements of the system could be:
1. To implement a login feature which is the 1st layer of security.
2. To allow for different views for each type of user.
3. To allow for new stores to be added.
4. To allow for editing of stores.
5. To allow stores to be removed.
6. To allow for items to be removed.
7. To allow for editing of items.
8. To make the application more user interactive by adding some helpful text throughout
the application to guide the user.
9. To properly design the GUI of the application to suit any computer and still look good.
Challenges Faced
The challenges faced by the researcher during the development of this application is as such:
1. The researcher only has basic knowledge of Java language therefore the researcher had
to discover new concepts to fulfill the requirements of this application.
2. The researcher has not been programming in Java for almost a year therefore the
researcher had to brush up on a lot of the Java syntax and programming concepts.
3. The researcher had to resort to manually creating the GUI rather than the more
preferable way of drag-and-drop to create the GUI as the codes would be more complex
if the latter method was used.
4. The researcher had to relearn a lot of the design patterns and really analyze them so as
to fit them in this application.
5. The researcher had to constantly solve minimal errors in the code by looking through
forums and books thus wasting precious development time.
6. As the GUI was created manually, the researcher had to do a lot of iteration to make
sure the GUI looks and functions properly.
28
Factory Method Pattern allows the sub-classes to choose the type of objects to create.
Secondly, the Abstract Factory pattern works around a super-factory which creates other
factories. This factory is also called as factory of factories. The Abstract Factory pattern comes
under creational pattern as this pattern also provides one of the best ways to create an object.
In Abstract Factory pattern, an interface is responsible for creating a factory of related objects
without explicitly specifying their classes. Each generated factory can give the objects as per the
Factory pattern.
The advantages of a Abstract Factory pattern is:
Abstract Factory Pattern isolates the client code from concrete (implementation) classes.
In the shopping mall application, this pattern is used to create the store factories while
providing multiple layers of abstraction and also a form a security. Furthermore, this pattern
helped with keeping the objects consistent.
29
Singleton Pattern
The Singleton pattern is one of the simplest design patterns in Java. Just like Factory Method
pattern and Abstract Factory patter, this type of design pattern comes under creational pattern
as this pattern provides one of the best ways to create an object. This pattern involves a single
class which is responsible to create an object while making sure that only single object gets
created. This class provides a way to access its only object which can be accessed directly without
need to instantiate the object of the class.
The advantages of the Singleton pattern is:
Saves memory because object is not created at each request. Only single instance is
reused again and again.
In the shopping mall application, this pattern is used to saved memory during runtime.
Furthermore, the researcher had an easier time to refer to objects.
Observer Pattern
The Observer pattern is used when there is one-to-many relationship between objects such as if
one object is modified, its depenedent objects are to be notified automatically. Observer pattern
falls under behavioral pattern category.
The advantages of of the Observer Pattern are:
Can reuse subjects without reusing their observers and vice versa.
In the shopping mall application, this pattern is used to notify the registered customers when
a new item is added to a store.
30
Command Pattern
The Command pattern is a data driven design pattern and falls under behavioral pattern
category. A request is wrapped under an object as command and passed to invoker object.
Invoker object looks for the appropriate object which can handle this command and passes the
command to the corresponding object which executes the command.
The advantages of the Command Pattern are:
It separates the object that invokes the operation from the object that actually performs
the operation.
It makes easy to add new commands, because existing classes remain unchanged.
In the shopping mall application, the command is pattern is used to undo a previous action
making the application more user interactive.
31
References
Architecture-Driven Modelling Methodologies. (2011). In: Proceedings of the 2011
conference on Information Modelling and Knowledge Bases XXII. Amsterdam,
Netherlands: IOS Press, p.98.
Deitel, P. and Deitel, H. (n.d.). Java how to program.
Gamma, E. (1995). Design patterns. Reading, Mass.: Addison-Wesley.
Holzner, S. (2006). Design patterns for dummies. Hoboken, N.J.: Wiley.
Lucidchart, (2014). Use Case Specification - Example and Template (UML). [online]
Available at: https://www.lucidchart.com/pages/use-case-specification-exampleand-template-UML [Accessed 2 Dec. 2015].
WhatIs.com, (2015). What is use case diagram (UML use case diagram)? - Definition
from WhatIs.com. [online] Available at:
http://whatis.techtarget.com/definition/use-case-diagram [Accessed 2 Dec. 2015].
32
Appendix
The program can be added to Netbeans IDE as a new project and run from there.
33