Assignment 2 for Advanced Programming 1651, Assignments of C Sharp Programming

Assignment 2 for Advanced Programming 1651

Typology: Assignments

2021/2022

Available from 07/29/2022

tri-minh-1
tri-minh-1 🇻🇳

4.7

(144)

36 documents

1 / 20

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
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
PHAN MINH TRI
Student ID
GCD201632
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
Grading grid
P3
P4
M3
M4
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Assignment 2 for Advanced Programming 1651 and more Assignments C Sharp Programming 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name PHAN MINH TRI 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 Grading grid P3 P4 M3 M4 D3 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Table of Figures Figure 1: Class Diagram ................................................................................................................................................. 5 Figure 2: Interface IInformation .................................................................................................................................... 5 Figure 3: Car Class ......................................................................................................................................................... 6 Figure 4: ElectricCar Class.............................................................................................................................................. 6 Figure 5: Store Class ...................................................................................................................................................... 7 Figure 6: Singleton pattern structure .......................................................................................................................... 14 Figure 7: Factory pattern structure ............................................................................................................................. 15 Figure 8: Decorator pattern structure ......................................................................................................................... 16 Figure 9: Adapter pattern structure ............................................................................................................................ 17 Figure 10: Command pattern structure ...................................................................................................................... 18 Figure 11: Iterator pattern structure........................................................................................................................... 19

Chapter 1 – Introduction

❖ The preceding report covered everything relevant to OOP, including OOP theories, OOP characteristics, etc. In addition, a basic introduction to UML and class connections was presented. ❖ To put that information into reality, I will choose a specific scenario to apply to apply program to in this report. The UML class diagram will be provided in the report to aid comprehension. Finally, in future projects, a brief introduction to the design pattern will be employed.

Chapter 2 – Scenario Analysis

I. Scenario ❖ My friend just requested me to assist them with a car management program for their store. I'm planning to create an app that will save the list of cars in the store. This software enables users to add new cars by inputting car information such as ID, Brand, Model, and Price. Furthermore, the program allows you to search for cars by brand or model, delete cars from the list, and update car information based on the car's ID.

II. Class Diagram ❖ This is class diagram of Car Management program, including 4 classes: Car (Parent class), ElectricCar (Children class), IInformation (Interface) and Store class which contains CRUD functions Figure 1 : Class Diagram

  • First, there is interface class IInformation, which has PrintInformation function, is used for print information of other class, which inherited this interface, to screen Figure 2 : Interface IInformation

all cars by their brand, FindCarbyModel() for searching specific car by its model, RemoveCarbyModel() for deleting car in list by its model which user enter and UpdateCarbyID() for editing information of car by its id which user input into program. Figure 5 : Store Class

Chapter 3 – Implementation

I. Code

1. Interface

❖ In this interface, it just implementation the function PrintInformation() for other class inherits and build their login on it function.

2. Car Class

❖ Fields includes id, brand, model, and price according to the diagram ❖ Properties of these fields to encapsulate and set the way to access to fields ❖ Constructor of the Car class which generate all values of cars by the properties which covered before ❖ Function PrintInformation() to print information of cars

❖ RemoveCar() Function: this function is used for deleting car in the list which has the same model which the model the user input to the program ❖ PrintInformation() Function: this function, which inherits from IInformation interface, is used for print all cars in the list to the screen ❖ FindCarbyModel() Function: this function is used for searching specific car by the model which user has enter to the program, is equals to the first one the cars list

❖ FindCarbyBrand() Function: this function is used for searching all cars of the brand which equals to the brand user input to the program II. Program Screenshots ❖ Interface of the program ❖ AddCar Function

  • Add normal car

❖ UpdateCarbyId() Function:

  • Before editing the car, which has ID = 11
  • After updating ❖ RemoveCarbyModel() Function: I will delete car which has model “Raize”
  • Before deleting
  • After deleting

Chapter 4 – Discuss a range of design patterns with relevant

examples of creational, structural, and behavioral pattern types

I. Creational patterns

1. Singleton pattern

❖ The singleton design pattern ensures that a class has only one instance while offering a global access point to this instance. ❖ The Singleton pattern handles two issues at once, therefore breaching the Single Responsibility Principle:

  • Ensure that a class has just a single instance: The most typical reason is to restrict access to a shared resource. Because a constructor call must always return a new object by design, this behavior is difficult to perform with a conventional constructor.
  • Provide a global access point to that instance: The Singleton design allows you to access an object from wherever in the code. It also prevents that instance from being replaced by other code and crashes if it is accidently overwritten with an incorrect version of the program's memory management system. ❖ Solutions of Singleton pattern
  • To prevent other objects from using the “new” operator with the Singleton class, make the default constructor private.
  • Create a constructor-like static construction method. This function invokes the private constructor to build an object and stores it in a static field. All subsequent calls to this function will return the cached object. ❖ Example: The government illustrates the Singleton pattern perfectly. A country may only have one official government. Regardless of the identities of those who form governments, the term "The Government of X" is a worldwide point of access that identifies the group in power. ❖ Structure Figure 6 : Singleton pattern structure

II. Structural patterns

1. Decorator pattern

❖ Decorator is a structural design pattern that allows you to add new behaviors to objects by wrapping them in special wrapper objects that contain the behaviors. ❖ Structure Figure 8 : Decorator pattern structure

  • The Component specifies the shared interface for wrappers and wrapped objects.
  • Concrete Component is a class of wrapped objects. It describes the fundamental behavior, which decorators can modify.
  • The Base Decorator class has a field for referencing a wrapped object. The field's type should be specified as the component interface so that it can include both concrete components and decorators. The base decorator delegated all activities to the wrapped object.
  • Concrete Decorators define additional behaviors that may be dynamically applied to components. Concrete decorators override base decorator methods and perform their functionality either before or after invoking the parent method.

2. Adapter pattern

❖ The adapter design pattern allows items with mismatched interfaces to interact. ❖ You can make an adaptor. This is a special object that transforms the interface of one object so that another object may comprehend it. An adaptor encircles one of the items to conceal the complexities of conversion occurring behind the scenes. The wrapped object is completely unaware of the adaptor. ❖ Adapters may enable objects with different interfaces communicate by converting data into other representations. The following is how it works:

  • The adapter receives an interface that is compatible with an existing object.
  • The existing object can safely call the adapter's methods by using this interface.
  • When the adapter receives a call, it forwards the request to the second object in the format and sequence that the second object expects. ❖ Structure Figure 9 : Adapter pattern structure
  • Client is a class that holds the program's current business logic.
  • The Interface defines a protocol that other classes must follow to work with the client code.
  • The Service class is quite handy (usually 3rd-party or legacy). This class cannot be used directly by the client due to an incompatible interface.
  • The Adapter class implements the client interface while enclosing the service object. The adapter takes client calls through the adapter interface and converts them into calls to the wrapped service object in a format that the adapter understands.
  • If the client interface is used, the client code is not tied to the concrete adapter class. This allows you to incorporate new types of adapters into the application without disrupting the old client code. This is useful when the interface of the service class is altered or replaced.
  • The Receiver class provides some business logic. Almost any item may serve as a receiver. Most commands just manage the specifics of how a request is given to the receiver, while the receiver itself handles the real work.
  • The Client builds and configures concrete command objects. The client must supply all request arguments, including a receiver instance, into the command's constructor. Following that, the resultant command can be associated with one or more senders.

2. Iterator pattern

❖ Iterator is a behavioral design pattern that allows you to explore collection components without releasing their underlying representation (list, stack, tree, etc.). ❖ Structure Figure 11 : Iterator pattern structure

  • Iterator (AbstractIterator) specifies an interface for navigating and accessing items
  • Concretelterator (Iterator) implements the Iterator interface and keeps track of the aggregate's current location throughout traversal.
  • Aggregate (AbstractCollection) specifies a method for generating an Iterator object
  • ConcreteAggregate (Collection) implements the Iterator creation interface to return a ConcreteIterator instance

References

Dofactory, 2022. C# Iterator. [Online] Available at: https://www.dofactory.com/net/iterator-design-pattern [Accessed 1 July 2022]. Refactoring, 2022. DESIGN. [Online] Available at: https://refactoring.guru/design-patterns [Accessed 1 July 2022].