






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







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 Tran Quang Khai Student ID GCH Class GCH 0907 Assessor name Doan Trung Tung 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 khai Grading grid P1 P2 M1 M2 D1 D
Grade: Assessor Signature: Date: Lecturer Signature:
According to assignment 1, this report will represent about the decorator design pattern’s scenario, UML diagram base on scenario with explanation. This report is also present about the implementation of the decorator design pattern using c# language and visual studio code IDE with .net framework.
2WheelsCustom is a motorbike shop, there are many types of motorbike (chopper, cruiser, sport, …) in the ware house. But many of biker doesn’t want to buy something traditional, something fixed, something is too popular. So, the 2WheelsCustom has provided the tuning service for the base motorbike such as power up the engine, change the brake pedal, change the tire type without getting penalty from police. From the criteria above, I decide to use decorator pattern to develop the 2WheelsCustom application. Why is decorator? Because with decorator, the program doesn’t have to create many fixed classes for each motorbike type with each of tuning option, it will only have to wrap the type and tuning based on customer’s choice together.
Figure 1. 2WheelsCustom diagram There are two main elements in this diagram, the core part (left side) and the decorator part (right side), the decorator part will wrap and attach the additional responsibilities into the core part and both of them will implement a same interface that defines the objects can have responsibilities added to them
dynamically. In this case, the core part is the three class on the left side (Chopper, Cruiser and Sport), they are the body of the motorbike, which can be added more upgrade from the decorator part. And the decorator part (MotorbikeDecoration and 4 children class Engine, Break, Tire and Suspension), all of them is the upgrade for the motorbike body above. And all the object defined class will have the two operations are price and displaydescription to calculate the final object price and its description.
Body class Three body class (Chopper, Cruiser and Sport) will implement the motorbike class and its operation and return each data for each body type. MotorbikeDecorator class
This is the operation that will contain all the other operation in the program and make them follow a progress. Firstly, user will see a menu of motorbike body, then they can choose it by enter the number in front of the body. The program will get the entered number from user and check if the entered number is 0 or from 1 to 3, if the number is 0 the program will close, otherwise it will do the task below.
It will assign the motorbike object base on the number from user then go to the choose upgrade part. In upgrade part, it’s also print the menu of upgrade option.
The print product operation may need an if else condition because the user can buy a motorbike without upgrade anything. And after the print progress, the program will remove the created object and user can choose a new motorbike immediately.
The motorbike body option with user choice is sport motorbike The upgrade menu with user choice is engine upgrade
User choose done to complete the upgrade progress, and the program print the price and the description of the final motorbike.
Similar pattern with decorator The similar pattern of decorator design pattern may be proxy pattern, because the concept of both is revolve idea of wrapping an instance of an existing interface (body as my scenario) with a class that implements that same interface and delegates their function calls to the same functions on their body instance. Why decorator is the most suitable for my scenario As I mentioned in the scenario, the decorator pattern let me creating new object without create the fixed class from the source code before, It make the code less verbose and more clearly. It’s also help the 2WheelsCustom gather the creative opinion from user, in this progress, the program is only have to wrap user’s opinion and 2WheelsCustom can copy it.
Advantage