Download Assignment 2-1651-Web Programming-Pass-IT- Greenwich and more Papers Web Programming and Technologies in PDF only on Docsity!
Higher Nationals in Computing
Advanced Programming
REPORT
Assessor name: Nguyễn Văn Sơn
Learner’s name: Nguyễn Ngọc Phú
Working together with: Trương Huỳnh Gia Hoàng, Nguyễn Hoàng Trọng Phát
ID: GCS 210331
Class: GCS1005A
Subject code: 1651
Assignment due: Assignment submitted:
ASSIGNMENT 2 FRONT SHEET
Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyễn Ngọc Phú Student ID GCS Class GCS1005A Assessor name Nguyễn Văn Sơn 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 D
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 LO 3 Implement code applying design patterns P3 Build an application derived from UML class diagrams. M3 Develop code that implements a design pattern for a given purpose. D3 Evaluate the use of design patterns for the given purpose specified in M3. LO4 Investigate scenarios with respect to design patterns P4 Discuss a range of design patterns with relevant examples of creational, structural and behavioral pattern types. M4 Reconcile the most appropriate design pattern from a range with a series of given scenarios. D4 Critically evaluate a range of design patterns against the range of given scenarios with justification of your choices.
1. Introduction
Continuing with Part 1 In this part, I will proceed to build the system prepared in the previous part, including
designing, implementing and using the necessary tools for deployment. After this section I will conduct a
system check and teach new users how to use the system effectively.
The library management application is built on the C# programming language that simplifies the library
management process, from entering book information, finding books, editing, deleting books, displaying all
book information. The application can be deployed on the desktop to meet the library management needs of
different units and organizations.
I use the console as the interface to the system. When the user boots the system will display a menu panel that
allows the user to select the functions they want through the displayed numbers(see the follow in figure). When
users enter or find information on the system, all information will be displayed on the screen. Otherwise, it
will display a message not found. My system is so simple it will be user friendly
P3 Build an application derived from UML class diagrams.
1.Implementation
1 .1Code
General Menu
This is the Menu that shows the user all the functions that the user wants to choose. The sequence numbers
will correspond to all the functions in the menu in turn. From the main menu this will link to the functions
created in the system
This is the part of the code that will perform the functions that the user chooses it will take the user to the
processing system of the function they have selected.
Menu of find a book
This is the part that will handle the search function by ID after selecting the system will ask the user to
enter the ID of the book to look for, if any, the system will return all books and information when the
system finds it, if not, it will Returns a book not found message
FindBookByTitle
Similar to the above function, this will handle the function of finding books by name
FindBookByAuthor
Similar to the two search functions above, this will handle finding books by author's name
Edit Book
This is the code that will handle the book's information editing function. First, when selecting the
function, the system will ask the user to enter the ID to edit the information, if found, the system will
display a section that allows the user to enter and change the book information such as name, author,
publication date. and category after entering and confirming the system will proceed to overwrite the
previous information with new information and save it if the system does not find the ID that the user
needs to find will display up (Not found!! )
DeleteBook
This is the part of the code that handles the function of deleting books from the system. When selecting
this function, the system will ask the user to enter the ID of the book to be deleted, if found, the system
will delete it as soon as the user confirms it, if not found, it will return NotFound!!
AddBorrowers
ShowAllBooks
This is the part of the code that will handle 2 parts, show all book and show all borrowers. the system will
display all the book information and show all the tenant information
FindBorrowersByName
Finally, the code will handle the function of finding people who borrow books by their name, the system
will ask to enter the name of the person to find, if found, the system will return the information that the
system found if it is not found, it will return " Not Found”
1. Program screenshots
Menu:
This is the Menu interface when the user starts the system here the user can choose any function they want2.
Menu of “Find a Book”
Menu of Find a book
This is the small menu interface of the book search section here to find books divided into three parts:
ID, name, also known as Title and author. Mistakenly wants to expand the user's search
Add a book
This is the first function of the system, which is to add new books. When this function is selected, the system
will ask to enter information. I have added some information to the system like ID, title, Author, date,
description and cate.
Next is the function to edit book information, when you select this function, the system will ask you to enter
the book ID, if there is, it will display the place to fill in the information you want to change, otherwise it will
return not found.
ShowAllBooks
This is the function to display all books on the screen. When this function is selected, the system will
print all books in the system.
DeleteBook
Here I have implemented the function to delete the book and show it to prove that I have deleted it
successfully
Add Borrowers
This is the function of adding new tenants in the same way as adding new books. I have added information
like ID, name, age, sex and phonenumber
EditBorrowrs
Here I make the function is to edit the user information in this function can change all the information
except the ID because it is unique and cannot be changed.
I perform the function to show all book borrowers to the screen. When using this function, the system
will print all the book tenants and the attached information.
DeleteBorrowers
Finally I implement delete function by entering ID if any will delete directly on confirmation otherwise return
not found. And I implemented the show function to prove that the delete function works fine.
Reusability: They allow for reusable code, saving
development time and effort.
Over-Engineering: Unnecessary complexity might
result from using patterns without a good
justification.
Flexibility: They offer flexibility in object creation
and make it simple to add or change object kinds.
Performance Overhead: Certain patterns could cause
a very minor performance overhead.
Testability: They increase testability by making it
easier to employ mock tests or test replicas.
Learning Curve: Understanding and instruction are
necessary to use design patterns.
2.3. Example
Singleton Pattern Example
Although the Singleton pattern was introduced by GoF, early implementations are known to be problematic
in multithreaded scenarios.
So here, we will follow a more optimal approach, using static inner class:
Here, we have created a static inner class that holds an instance of a Singleton class. It will only create one
instance when we call getInstance() and not when the outer class is loaded.
This is a widely used approach for a Singleton class because it requires no synchronization, is thread safe,
implements lazy initialization, and has relatively few prototypes.
Also, note that the constructor has an access modifier that is private. This is a requirement to create a Singleton
because when a public constructor means anyone can access it and start creating new instances.
Factory Method Design Pattern
In this example, we will create an interface Polygon that will be implemented by some specific classes. A
PolygonFactory will be used to find and retrieve objects of this type:
3. Structural design Pattern
3.1. Definition
These design patterns are centered on the composition of classes and objects. Inheritance is used by structural
class-creation patterns to create interfaces. Object composition techniques using structural object patterns are
described in order to create new functionalities.
Match interfaces of different classes
Separates an object’s interface from its implementation
A tree structure of simple and composite objects
Add responsibilities to objects dynamically
A single class that represents an entire subsystem
A fine-grained instance used for efficient sharing
Restricts accessor/mutator access
An object representing another object
3.2. Advantage and Disadvantage
Advantage Disadvantage
Modularity: Improve the division of duties and
organization of the code.
Increased Complexity: Can make the codebase
harder to get it and keep up.
Code Reusability: Encourage the use of pre-
existing classes and interfaces to build new, more
functional objects.
Performance Impact: A few designs may present
overhead and result in slower execution.