ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc, Essays (university) of Programming for Engineers

ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc

Typology: Essays (university)

2021/2022

Uploaded on 07/15/2022

quoc-vo-minh
quoc-vo-minh 🇻🇳

4.8

(13)

14 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 20: Advanced Programming
Submission date
29/06/2022
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Võ Minh Quốc
Student ID
GCD201870
Class
GCD0904
Assessor name
Pham Thanh Son
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
Quoc
Grading grid
P3
P4
M3
M4
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download ASSIGNMENT TWO - Advanced Programming (P) - Vo Minh Quoc and more Essays (university) Programming for Engineers in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20 : Advanced Programming Submission date 29 /06/2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Võ Minh Quốc Student ID GCD Class GCD0904 Assessor name Pham Thanh Son 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 Quoc Grading grid P 3 P 4 M 3 M 4 D 3 D 4

r Summative Feedback: r Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date:

Chapter 1 - Introduction

Everything related to OOP, including OOP ideas, OOP traits, and much more, was already covered in the last report. Additionally, a basic introduction to UML and the relationship between classes was provided. In order to put all of the knowledge from the previous report into practice, I will pick a specific scenario to apply a program to in this report. The UML class diagram will also be included in the report for easy comprehension. Finally, a brief section on the design pattern that will be used in future projects.

Chapter 2 - Scenario analysis. (P1)

1. Scenario:

I recently signed a contract with the FPT firm, and soon I'll be chosen to oversee a team of programmers as they create the company's shop management system. I have to build an application to keep a list of books in this shop management system. The system allows the user to input data on books and household appliances, including id, title, price, quantity, and... The system includes functions that customers need, such as adding, deleting, updating, and searching for book information.

2. Class diagram:

This is a class diagram including four classes: IInformation (interface), Shop (contains CRUD function), Book (Parent class), GoldenEditionBook (Children class).

  • As mentioned that the class IInformation is an interface, the function inside of it is PrintInformation() which is used for other class inheriting and then adding logic to printing information to screen.
  • Class Shop contains a list of book and CRUD functions, more specifically, those functions are Addbook() (Create), PrintInformation() (Read), FindBookById() (Read), FindBookByName() (Read), CheckId() (for check Id which is valid or not for when user enter), UpdateBookById() (Update), RemoveBookById() (Delete)
  • Class Book contains fields (id, title, author, price, and quantity), constructor, properties (Id, Title, Author, Price, and Quantity) for encapsulating field, and method PrintInformation() to print information.

As mentioned above, this class is the child class of Book class or we can say it is applied the inheritance which is one of the characteristics of OOP, it inherits everything in parent class (Book class), and also I mentioned that the Book class contains the property ‘Price’ with the ‘virtual’ key word for child class having ability to change the logic inside of it (this is a Polymophism characteristic of OOP). C. Shop class: Class diagram: As mentioned above, Shop class plays an essential role in the whole program, because it includes a list of book and CRUD function. Here is the specification of explanation

  • books: is the list to contain books inside
  • AddBook(): used for adding more book into list
  • PrintInformation(): is the function inheriting from the IInformation interface, which is changed the logic inside of it into the function for printing all of the information of all books.
  • FindBookById(): Each book has it unique id so I created this function in order to find the book in the most convenient way for user.
  • FindBookByName(): Each book has it own name, but their name can be the same, I create this function to find book by its name (means title) to keep track of how many books with the same name is entered.
  • CheckId(): Because id of each book is unique, so I created this function for checking id if it is duplicated or not, if duplicated, user will be asked to enter the other id for avoid two duplicated id in the ‘books’ list.
  • UpdateBookById(): It is hard to update book by its title, price, quantity but id of each book is unique, so I create this function to update book by its id.
  • RemoveBookById(): This is the last function to delete the book by its id. D. IInformation interface: Class diagram: As I mentioned above, this class is used for containing declarations of method ‘PrintInformation’, and two class ‘Book’ and ‘Shop’ inheriting this class in order to get this function and then changing the adding the logic inside of this function to meet their class’s functional requirement.

Chapter 3 - Implementation (P1)

1. Code:

In this part, I am going to show code of my program corresponding to the above class diagrams. A. Book class:

  • Fields: includes id, title, author, price, and quantity corresponding to the class diagram.
  • Method: This is a method for printing information of book. B. GoldenEditionBook class:
  • Constructor: This is a constructor of GoldenEditionBook based on its class parent (Book)
  • Properties: This is a property overrode to change the logic inside it. C. Shop:
  • List: This is the code for ‘books’ list
  • Constructor: This is the constructor for Shop class
  • Function:
    • Addbook(): This is the function for adding more book into list, inside of it, I call the function ‘CheckId’ to check id when user enter, if id is duplicated, the program will throw the exception for asking user to enter another id.
    • CheckId(): this is the function to check id by compare id in list with entered id.
    • RemoveBookById(): This is the function to delete book by its id, the id will be found first then deleted
    • PrintInformation(): This is the function inherited from the ‘IInformation’ interface, and then I added the logic inside it.

Below here is the code of IInformation interface:

  • It just includes the declaration of the method ‘PrintInformation()’.

2. Program screenshots:

A. Initial interface: When I run the program, it will return this interface. Although it is not user-friendly but, it contains enough options that user need. B. Add function: When I chose option 1 meaning add, the program will return to another options for user, they can choose ‘a’ for adding normal book, ‘b’ for adding golden edition book, ‘v’ for exiting. Then I chose ‘a’ and the program returned the interface for entering information, if entering information is successful, the program will return to adding menu option again.

If user enters the id, title, author which are not valid, the program will catch that and return the alert. After adding successfully, that book will appear in the list

D. Update: When I choose the option 6 and then enter information of the book which I need, the program will check if that book’s id is in the list or not, and then it will change the information of that book with that id corresponding to the id in the list, and print the alert. Before updating: After updating:

E. Delete: When I choose the option 5, and then enter the id of book which I want to delete, the program will find that book in list corresponding to the id entered, and delete it. Before deleting: After deleting:

  • Bridge Design Pattern
  • Composite Design Pattern
  • Proxy Design Pattern
  • Flyweight Design Pattern A. Singleton pattern: One of the most prominent design patterns in C# is the singleton design pattern. A class has just one instance in the program that offers a global point of access to it in this pattern. A singleton is a class that permits just one instance of itself to be produced and often provides straightforward access to that instance. (Alle, 2021) Advantages Disadvantages
  • Singleton pattern can implement interfaces. (Alle, 2021)
  • Can be lazy-loaded and has Static Initialization. (Alle, 2021)
  • It helps to hide dependencies. (Alle,
  • It provides a single point of access to a particular instance, so it is easy to maintain. (Alle, 2021)
  • Unit testing is a bit difficult as it introduces a global state into an application (Alle, 2021)
  • Reduces the potential for parallelism within a program by locking. (Alle,

Class diagram: On that class diagram, the class ‘Employee’ has only one instance which is Employee(), and function ‘GetInstance’ offers global access to ‘Employee()’ instance. B. Factory pattern:

The Factory Method Design Pattern offers an interface for producing an object but leaves it up to the classes that implement the interface to determine which class to instantiate. The Factory Pattern allows a class to defer instantiation to sub-classes. The factory pattern is used to replace class constructors by abstracting the object creation process so that the type of object created may be specified at run-time. (Alle, 2021) Class diagram:

  • Product: This defines the interface of objects the factory method creates
  • ConcreteProduct: This is a class that implements the Product interface.
  • Creator: This is an abstract class and declares the factory method, which returns an object of type Product. This may also define a default implementation of the factory method that returns a default ConcreteProduct object. This may call the factory method to create a Product object.
  • ConcreteCreator: This is a class that implements the Creator class and overrides the factory method to return an instance of a ConcreteProduct. C. Builder Pattern: The Builder design pattern decouples the development of a complicated item from its representation, allowing the same building process to produce several representations. (Anon., n.d.)