0% found this document useful (0 votes)
44 views

Unit 20 - Assignment Brief 2

The document provides details about an assignment to implement a library management system using object-oriented analysis and design (OOAD) and design patterns (DP). It includes a class diagram for the system showing classes for the library, users, books, librarian, and inherited book types. Code snippets show classes for the overall program, library management, library, admin, book, and user. The main tasks are to translate the class diagram into code, discuss relevant DPs and justify the choice made.

Uploaded by

Dung Bui
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Unit 20 - Assignment Brief 2

The document provides details about an assignment to implement a library management system using object-oriented analysis and design (OOAD) and design patterns (DP). It includes a class diagram for the system showing classes for the library, users, books, librarian, and inherited book types. Code snippets show classes for the overall program, library management, library, admin, book, and user. The main tasks are to translate the class diagram into code, discuss relevant DPs and justify the choice made.

Uploaded by

Dung Bui
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 20: Advanced Programming

Submission date 20/12/2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Bùi Minh Dũng Student ID GCS210635

Class GCS0905C Assessor name

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.

Student’s signature

Grading grid

P3 P4 M3 M4 D3 D4
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

ASSIGNMENT 2 BRIEF
Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 2: Advanced Programming

Assignment title Application development with class diagram and design patterns

Academic Year 2021-2022

Unit Tutor Doan Trung Tung

Issue date 30 April 2019 Submission date 20/12/2022

Submission Format:

Page 2
Format: The submission is in the form of an individual written report. This should be written in a concise,
formal business style using single spacing and font size 12. You are required to make use of
headings, paragraphs and subsections as appropriate, and all work must be supported with
research and referenced using the Harvard referencing system. Please also provide a
bibliography using the Harvard referencing system.
Submission Students are compulsory to submit the assignment in due date and in a way requested by the
Tutors. The form of submission will be a soft copy in PDF posted on corresponding course of
http://cms.greenwich.edu.vn/ together with zipped project files.
Note: The Assignment must be your own work, and not copied by or from another student or from
books etc. If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you
must reference your sources, using the Harvard style. Make sure that you know how to reference properly,
and that understand the guidelines on plagiarism. If you do not, you definitely get fail

Assignment Brief and Guidance:

Scenario: (continued from Assignment 1) Your team has shown the efficient of UML diagrams in OOAD
and introduction of some Design Patterns in usages. The next tasks are giving a demonstration of using
OOAD and DP in a small problem, as well as advanced discussion of range of design patterns.

Tasks:
Your team is now separated and perform similar tasks in parallel. You will choose one of the real
scenarios that your team introduced about DP in previous phase, then implement that scenario based
on the corresponding class diagram your team created. You may need to amend the diagram if it is
needed for your implementation. In additional, you should discuss a range of DPs related / similar to
your DP, evaluate them against your scenario and justify your choice.

In the end, you need to write a report with the following content:
• A final version of the class diagram based on chosen scenario which has potential of using DP.
• Result of a small program implemented based on the class diagram, explain how you translate
from design diagram to code.
• Discussion of a range of DPs related / similar to your DP, evaluate them against your scenario
and justify your choice (why your DP is the most appropriate in that case).

Learning Outcomes and Assessment Criteria

Pass Merit Distinction

LO3 Implement code applying design patterns

Page 3
P3 Build an application M3 Develop code that D3 Evaluate the use of
derived from UML class implements a design pattern design patterns for the
diagrams. for a given purpose. given purpose specified in
M3.

LO4 Investigate scenarios with respect to design patterns

P4 Discuss a range of M4 Reconcile the most D4 Critically evaluate a


design patterns with appropriate design pattern
range of design patterns
relevant examples of from a range with a series of
creational, structural and given scenarios. against the range of given
behavioral pattern types. scenarios with justification
of your choices.

Table of content

Page 4
Assignment 2

P3.

Scenario
I was asked to create a management system. The system that I decided to develop is the library management
system. The system can help librarian to perform vital administrative tasks, including creating, reading,
updating, and deleting books. With the help of this system, librarians can keep track of books in the library,
including borrowed books and returned books. Users can utilize this system to search, borrow books, and

Page 5
then they must return them. With the search function, users can search for books they want to find by their
ID, title, and author’s name.
Some feature functions:
• Display menus. To be more specific, in my project, there are a total of 4 menus.
• Add function: to add information about books, such as ID, title, category, and author.
• View function: to show all information about books that have been added.
• Update function: to edit the information about books that is in the list.
• Delete function: to remove a specified book as users want.
• Search function: to find specified books as users want.
• Borrow book: to borrow a book in the library if they exist.
• Return book: to return the borrowed book to the library.

Class diagram

Page 6
The class diagram for the system briefly describes the properties, methods, and connections between objects
in the Library Management System class.
Library class: It supervises all activities. Software is mostly created with the organization in mind. Password
and Username are attributes. Register(), Login(), and Logout() are the methods.
• User class: It oversees all user actions. Name and ID are attributes. Searchbooks(), Borrowbooks(),
Returnbooks(), and Viewbooks() are the methods.

Page 7
• Book class: It controls every aspect of books. It is a fundamental component of the system. Name,
ID, and Author name are the attributes. Displaybooks() is the method.
• Librarian class: It oversees all librarian operations. Name and ID are attributes. Addbooks(),
Deletebooks(), Updatebooks(), and Viewbooks are the methods.

It is notable to see from the diagram that I create three classes that inherit from the abstract class Book.
• Education
▪ Attributes: the class creates attributes called “ID”, “title”, and “author”.
▪ Functions: Displaybooks().
• Comic
▪ Attributes: the class creates attributes called “ID”, “title”, and “author”.
▪ Functions: Displaybooks().
• Magazine
▪ Attributes: the class creates attributes called “ID”, “title”, and “author”.
▪ Functions: Displaybooks().

Implementation

Code
There are several classes in my project.
• Program: contain the main menu of the system.
• Librarymanagement: this class contains the function for the admin to log in to perform essential
administrative tasks.
• Library: contain the functions for the users to register and then login into the system to perform some
personal tasks, including searching, viewing, borrowing, and returning books to the library.
• Admin: contain output function to show all the information.
• Book: contain all the information of the books and output function to show all the information.
• User: contain some user’s functions such as search, view, borrow, and return.

Page 8
Library class

These are all the attributes in the class and also the constructor of this class. In specific, attributes in the class
are username, password, username1, and password1.
This class will inherit from the User class.

This function will allow a user to register for a new account. The information of a user will be saved into the
User.txt file.

Page 9
This function will allow users to login into the system if they already have accounts. To authorize the users, I
use the StreamReader to read the User.txt file to compare if the user’s input username and ‘s input password
are the same as those in the file. Firstly, I will assign a variable type Boolean to false. If the user enters the
correct username and password, I will assign the variable to true, and then if it is true, the menu of the user
will appear to allow the user to perform personal tasks.

Page 10
This is the menu that will be called if the user chooses to access the system as a user. This menu will be put
in the program.cs class (will be discussed after).

Next, I will discuss about the program.cs class.

Page 11
In this class, I will call the Librarymanagement class and Library class and set the to manage and library
respectively. Then, I assign a new variable to 0 named choice type integer. In this class, I will create a menu
with the help of the switch-case statement. If the user chooses the first option, the Menu() function in the
Library class will be called. If the second choice is selected, the LoginAdmin() function in the
Librarymanagement class will be called (will be discussed later). This menu will stop if the 3rd option is
chosen.

Next, moving to the Admin class.

Page 12
These are all the attributes in the class and also the constructor of this class. In specific, attributes in the class
are ID, Title, Category, and Author.
This class will inherit from the Book class.

This is the Input2() function which allows users to input ID, Title, Category, and Author.
The Output() function will show all the information from the list that is input from the users.

Next, moving to the Librarymanagement class.

These are all the attributes in the class and also the constructor of this class. In specific, attributes in the class
are admin, adminpassword, admin1, and adminpassword1.
This class will inherit from the Admin class.
In this class, I will create a list type Admin to store information.

Page 13
Firstly, I will call the Admin class and set it to ad, and then I will call the Input2() function from the Admin
class. After the input process, I will add those information to the list that has been created before. After that,
I will convert this list into a JSON file and store it in the Book.json file.

Firstly, I will assign a new variable result to an empty string. Then, I will convert the JSON file which has
been created before to a list. After that, I will loop over the list and show all the information from the list.

Page 14
This is the function that allows admins to log in to the system. To authorize, I will read the Admin.txt file
and then compare the information inside that file with the input admin username and admin password. If
they are the same, the assigned-false variable named done will be changed to true. If it is true, the menu2()
function will be called.

To search for an id in the list, admins must enter an id to search, if that id is the same as the one in the list,
the result id’s information will be shown.

Page 15
Call the SearchBook() function and then put inside it a parameter called id. This function will be assigned to
the Admin type variable named a. After that, I will start the do-while loop to update the information of the
entered id. Then, the assigned-false variable named done will be changed to true. The loop will stop if the
done variable is true.

Call the SearchBook() function and then put inside it a parameter called id. This function will be assigned to
the Admin type variable named a. After that, if the a is not null the list will remove the entered id.

Page 16
Page 17
Firstly, I will assign the variable named choice type integer to 0. Then, I will start the do-while loop to repeat
the menu until the 6th choice is selected. The first choice is to add books, the second one is to view books,
the third one is to update books, the fourth one is to delete books, and the fifth one is to search books.

Next moving to the class Book.

These are all the attributes in the class and also the constructor of this class. In specific, attributes in the class
are ID, Title, Category, and Author.
With the presence of the abstract method Output() which will be later overridden by other classes that use
inherit from this class.

Next, moving to the User class.

This class will inherit from the Admin class.


I will create a list named Deserializelist type Admin and a list named Temp type Admin.

Page 18
This function Output() is overridden from the one in the Book class. I will convert the JSON file to the list,
and then I will loop over the list to show the information on books. Then I will create the function named
ViewBooks() and then call the function Output().

To search by ID, users must enter an ID to search, and if it is the same as the one in the file-converted list, all
the ID’s information will be shown. The assigned-false variable named done will be changed to true. The do-
while loop will stop if the variable done is true.

Page 19
This function’s principle is also the same as the SearchbyID() function, with only the difference is that users
must enter the author’s name instead of the ID.

This function’s principle is also the same as the SearchbyID() function, with only the difference is that users
must enter the book’s title instead of the ID.

Page 20
This is the function to allow users to borrow a book from the library. To do this, users must enter an ID, and
if the ID is in the file-converted list, users can borrow that book. Then, the list will remove the book and
store the information about that book in the list named Temp. The do-while loop will stop when the variable
done is true.

Page 21
In this ReturnBook() function, users must also enter an ID, and if that ID is in the JSON file named Temp.
After that, the book will be added to the Deserializelist and then write it in the file to store that information.

Page 22
Firstly, I will assign a new variable named choice type integer to 0. The 1st choice is to view books, the 2nd
one is to search books by ID, the 3rd one is to search books by author’s name, the 4th one is to search books
by book’s name, the 5th one is to borrow books, and the 6th one is to return books. The menu will stop if
users choose the 7th choice.

Screenshots of the program

This is the main menu of the program.

Page 23
If I choose the 1st choice, the menu will change to the submenu that allow users to register or login into the
system.

When I register and login successfully, the other submenu of users will appear which will allow users to
perform some personal tasks.

Page 24
This is the book that I have already added and saved in the JSON file.

This is the result of the SearchbyID() function.

Page 25
This is the Borrow() function. As can be seen from the figures, the book has been removed from the list.

Now, let’s see if the users can return the borrowed book to the library.

Page 26
Now let’s move to the admin function.

Page 27
As can be seen from the figure, I successfully log in to the system.

Books are added to the list.

This is the books in the list.

Page 28
Book is updated.

Book is removed.

P4.
Design pattern definition
A design pattern is a generic, repeatable solution to a frequent issue in software design that is used in
software engineering. A design pattern isn't a finalized product that can be written in code right away. It is a
description or model for problem-solving that may be applied in a variety of circumstances.

Purpose of design pattern


By offering tried-and-true development paradigms, design patterns help hasten the development process.
Effective software design entails taking into account problems that might not show up until later in the
implementation process. For programmers and architects who are familiar with the patterns, the reuse of

Page 29
design patterns helps to eliminate minor flaws that can lead to large difficulties and enhances code
readability.
People frequently only know how to use specific software design strategies on particular types of issues. It is
challenging to use these strategies for a wider variety of issues. Design patterns offer broad-based answers
that are explained in a way that does not call for specifics related to a specific issue.
Additionally, patterns enable engineers to discuss software interactions using well-known, widely accepted
terms. Over time, common design patterns can be strengthened, becoming more durable than ad hoc designs.

There are three kinds of design pattern:

Creational pattern
Class instantiation is the central theme of these design patterns. This pattern may be further broken down
into patterns for creating classes and patterns for creating objects. While class-creation patterns successfully
employ inheritance throughout the instantiation process, object-creation patterns successfully use delegation.

There are some types of creational design pattern:


• Abstract Factory
Creates an instance of several families of classes
• Builder
Separates object construction from its representation
• Factory Method
Creates an instance of several derived classes
• Object Pool
Avoid expensive acquisition and release of resources by recycling objects that are no longer in use
Page 30
• Prototype
A fully initialized instance to be copied or cloned
• Singleton
A class of which only a single instance can exist
Abstract Factory Design Pattern

Structure:
Each Factory Method for a product is specified by the Abstract Factory. The new operator and the relevant,
platform-specific product classes are both included in each Factory Method. A class that derives from the
Factory is then used to model each "platform".

Example:
The Abstract Factory's function is to offer a creation interface for groups of related items without defining
specific classes. The sheet metal stamping machinery used in the production of Japanese cars has this
pattern. An Abstract Factory uses stamping machinery to make vehicle body pieces. For various automobile

Page 31
models, the same equipment is used to stamp right- and left-handed doors, right- and left-handed front
fenders, right- and left-handed hoods, etc. The concrete classes generated by the equipment may be changed
in three minutes by using rollers to replace the stamping dies.

Structural design pattern


These design patterns are centered on the composition of classes and objects. Inheritance is used by
structural class-creation techniques to create interfaces. Object composition techniques using structural
object patterns are described in order to create new functionalities.

• Adapter
Match interfaces of different classes
• Bridge
Separates an object’s interface from its implementation
• Composite
A tree structure of simple and composite objects
• Decorator
Add responsibilities to objects dynamically
• Facade
A single class that represents an entire subsystem
Page 32
• Flyweight
A fine-grained instance used for efficient sharing
• Private Class Data
Restricts accessor/mutator access
• Proxy
An object representing another object

Facade Design Pattern

Structure:
Facade injects a wrapping that tames the amorphous and baffling mass of software into a "riddle wrapped in
an enigma veiled in mystery."

SubsystemOne and SubsystemThree do not interact with the internal components of SubsystemTwo. They
use the SubsystemTwoWrapper "facade" (i.e. the higher level abstraction).

Page 33
Example:
A uniform, higher level interface to a subsystem is defined by the facade, making it simpler to utilize. When
making a catalog purchase, customers come across a Facade. The customer dials one number and gets
through to a customer support agent. The customer care agent serves as a Facade, acting as an interface
between the billing, shipping, and order fulfillment departments.

Page 34
Behavioral design pattern
The communication between Class's objects is the focus of these design patterns. The behavioral patterns
that are most explicitly focused on inter-object communication.

• Chain of responsibility
A way of passing a request between a chain of objects
• Command
Encapsulate a command request as an object
• Interpreter
A way to include language elements in a program
• Iterator
Sequentially access the elements of a collection
• Mediator
Defines simplified communication between classes
• Memento
Capture and restore an object's internal state
• Null Object
Designed to act as a default value of an object
• Observer
A way of notifying change to a number of classes
• State
Alter an object's behavior when its state changes
• Strategy
Page 35
Encapsulates an algorithm inside a class
• Template method
Defer the exact steps of an algorithm to a subclass
• Visitor
Defines a new operation to a class without change

Strategy Design Pattern

Structure:
The interface object might reflect the client's expected method signatures or an abstract base class. The
inheritance hierarchy stands in for dynamic polymorphism in the first scenario. In the latter instance, the
inheritance tree stands in for static polymorphism and the Interface object for client-side template code.

Example:
A collection of interchangeable algorithms are defined by a strategy. An example of a strategy is the means
of transportation to an airport. Driving one's own vehicle, using a cab, an airport shuttle, a city bus, or a
limousine service are some choices. Subways and helicopters are additional options for getting to some
airports' terminals. A passenger can reach the airport using any of these methods of transportation, and they
are all interchangeable. The traveler's Strategy must take into account trade-offs between price, comfort, and
time.

Page 36
Page 37

You might also like