Tải bản đầy đủ (.pdf) (106 trang)

Information Technology Assignment 2 Unit Advanced Programming.pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.21 MB, 106 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

<b> </b>

<b>BTEC FPT INTERNATIONAL COLLEGE</b>

<b>INFORMATION TECHNOLOGYASSIGNMENT 2</b>

<b>UNIT: ADVANCED PROGRAMMING</b>

<b>STUDENT : HO TAN RINCLASS : IT16101STUDENT ID : BDAF200038</b>

<b>SUPERVISOR : NGUYEN HOANG ANH VU</b>

<b>Da Nang, December 2022</b>

</div><span class="text_page_counter">Trang 2</span><div class="page_container" data-page="2">

<b> ASSIGNMENT 2 FRONT SHEET</b>

<b>QualificationBTEC Level 4 HND Diploma in ComputingUnit number </b>

<b>Re-Date received (2nd submission)</b>

<b>Student name </b>

<b>HO TAN RIN (Leader)</b>

<b>DOAN XUAN DUYEN (Member)</b>

<b>PHAM MINH THONG (Member)</b>

<b>PHAN ANH TUAN (Member)</b>

<b>PHAN NGOC CHINH (Member)</b>

<b>Grading grid:</b>

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

❒Summative Feedbacks: ❒

<b>Resubmission Feedbacks:</b>

<b>Internal Verifier’s Comments:</b>

<b>Signature & Date:</b>

</div><span class="text_page_counter">Trang 4</span><div class="page_container" data-page="4">

<b>OBSERVATION RECORD</b>

<b>Student 1HO TAN RIN (Leader)</b>

<b>Description of activity undertaken </b>

<b>Assessment & grading criteria </b>

<b>How the activity meets the requirements of the criteria </b>

<b>Student signature: TAN RINDate: 14/12/2022</b>

<b>Assessor signature: Date: </b>

<b>Assessor name: Nguyen Hoang Anh Vu</b>

<b>Student 2DOAN XUAN DUYEN (Member)</b>

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

<b>Assessment & grading criteria </b>

<b>How the activity meets the requirements of the criteria </b>

<b>Student signature: XUAN DUYENDate: 14/12/2022</b>

<b>Assessor signature: Date: </b>

<b>Assessor name: Nguyen Hoang Anh Vu</b>

<b>Student 3PHAM MINH THONG (Member)</b>

<b>Description of activity undertaken </b>

</div><span class="text_page_counter">Trang 6</span><div class="page_container" data-page="6">

<b>How the activity meets the requirements of the criteria </b>

<b>Student signature: MINH THONGDate: 14/12/2022</b>

<b>Assessor signature: Date: </b>

<b>Assessor name: Nguyen Hoang Anh Vu</b>

<b>Student 4PHAN NGOC CHINH (Member)</b>

<b>Description of activity undertaken </b>

</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">

<b>How the activity meets the requirements of the criteria </b>

<b>Student signature: NGOC CHINHDate: 14/12/2022</b>

<b>Assessor signature: Date: </b>

<b>Assessor name: Nguyen Hoang Anh Vu</b>

<b>Student 5PHAN ANH TUAN (Member)</b>

<b>Description of activity undertaken </b>

<b>Assessment & grading criteria </b>

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="8">

<b>Student signature: ANH TUANDate: 14/12/2022</b>

<b>Assessor signature: Date: </b>

<b>Assessor name: Nguyen Hoang Anh Vu</b>

</div><span class="text_page_counter">Trang 9</span><div class="page_container" data-page="9">

<b>TABLE OF CONTENT</b>

<b>INSTRUCTOR/ SUPERVISOR/ ASSESSOR……….i</b>

<b>OBSERVATION RECORD……….………iv</b>

<b>TABLE OF CONTENT ………ix</b>

<b>LIST OF TABLES AND FIGURES……….xi</b>

<b>LIST OF ACRONYM……….xii</b>

<b>INTRODUCTION ………..1</b>

CHAPTER 1 IMPLEMENT CODE APPLYING DESIGN PATTERNS………..2

1.1 Build an application derived from uml class diagrams (P3)………. 2

1.1.1 Analysis the chosen scenario………. 2

1.1.2 OOP code implementation……… 3

1.1.3 Java Code Implements……….3

1.1.4 Result Of Code……… 12

1.2 Develop code that implements a design pattern for a given purpose M3……… 18

1.2.1 Comparison between class diagram before using design patterns and after using design patterns………. 18

1.2.2 Apply Singleton pattern and JDBC to the project……….. 20

1.2.3 Why use Singleton for the project……… 33

CHAPTER 2 INVESTIGATE SCENARIOS WITH RESPECT TO DESIGN PATTERNS (LO4) 342.1 Discuss a range of design patterns with relevant examples of creational, structural and behavioural pattern types………. 34

2.1.1 Creational Pattern……….. 34

2.1.2 Structural Pattern ……….. 57

2.1.3 Behavioral patterns……… 69

</div><span class="text_page_counter">Trang 10</span><div class="page_container" data-page="10">

scenarios. (M4) 84

<b>CONCLUSION……….. 87</b>

<b>REFERENCES………. 88</b>

<b>CRITICAL EVALUATION………. 89</b>

</div><span class="text_page_counter">Trang 11</span><div class="page_container" data-page="11">

<b>LIST OF TABLES AND FIGURES</b>

Figure 1- 1 Management System...2

Figure 1- 2 Management System...3

Figure 1- 3 Add student...13

Figure 1- 4 Edit student...14

Figure 1- 5 Delete Student...15

Figure 1- 6 Sort student by gpa...16

Figure 1- 7 Sort student by name...17

Figure 1- 8 Show student...18

Figure 1- 9 Management System...19

Figure 1- 10 Management System...19

Figure 1- 11 XAMPP is running Apache and MySQL...20

Figure 1- 12 Create Databas...20

Figure 1- 13 Create Admin Table...21

Figure 1- 14 Set up admin table data...21

Figure 1- 15 Admin Table...22

Figure 1- 16 Create Admin Table...22

Figure 1- 17 Download JDBD Libraries...23

Figure 1- 18 DatabaseConnection Singleon...23

Figure 1- 19 Add admin...24

Figure 1- 20 Login Form...24

</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">

Figure 1- 22 Student Management Form...25

Figure 1- 23 Code Student Management Form...26

Figure 1- 24 Add Student Form...26

Figure 1- 25 Code Add Student Form...27

Figure 1- 26 Student Form...28

Figure 1- 27 Code Student Form...28

Figure 1- 28 Operation and Show Student Form...29

Figure 1- 29 Code Show Student Form...29

Figure 1- 30 Data in Admin table...30

Figure 1- 31 Login fail...30

Figure 1- 32 Login Management system...31

Figure 1- 33 Add Student in Management System...31

Figure 1- 34 Data in Student table...32

Figure 1- 35 Search, Update, Delete Student...32

Figure 1- 43 Object Adapter – Composition...57

Figure 1- 44 Class Adapter – Inheritance...58

Figure 1- 45 Bridge Pattern...62

</div><span class="text_page_counter">Trang 13</span><div class="page_container" data-page="13">

Figure 1- 47 Interpreter Design Pattern...69

Figure 1- 48 Components in the model...71

Figure 1- 49 Template Method Design Pattern...75

Figure 1- 50 Command...79

Figure 1- 51 singleton pattern...84

Figure 1- 52 Prototype Pattern...85

</div><span class="text_page_counter">Trang 14</span><div class="page_container" data-page="14">

Recently, we joined a software development business to assist them better document their internal software library, which had been produced with very little documentation. As a result of the inadequate documentation, the organization finds it challenging to use their code in various projects. Our job is to remedy this issue by demonstrating the value of UML diagrams in OOAD andthe application of Design Patterns.

As a result, we applied the student management object-oriented analysis and design to thistask to describe the characteristics of the object-oriented programming model. This student management program exhibits a number of OOP traits (such as: encapsulation, inheritance, polymorphism, overriding, overloading, etc.). The audience will next be introduced to certain design patterns by way of real-world examples; the related patterns are then shown in UML class diagrams. Let's find out in this assignment!

1

</div><span class="text_page_counter">Trang 15</span><div class="page_container" data-page="15">

<b>1.1 Build an application derived from uml class diagrams (P3)</b>

<b>1.1.1Analysis the chosen scenario</b>

This is the manager's development plan. Create a system that can simultaneously manage

subject teachers and students. When users start the app for the first time, they can choose to view

the student or professor management displays. The administration has the authority to add,update, and delete as well as perform query operations like search. You will then be able tocomprehend what you have seen. This is the manager's development strategy.

Figure 1- 1 Management System

Create a system that can simultaneously manage subject teachers and students. When users start the app for the first time, they can choose to view the student or professor management displays. The administration has the authority to add, amend, and remove data as well as perform query activities like searching. Then, we'll be able to recognize our modifications. This could be viewed as a management-simplifying strategy.

2

</div><span class="text_page_counter">Trang 94</span><div class="page_container" data-page="94">

Can do undo

Reduce connection dependencies between Invoker and Receiver

Allows encapsulation of requirements into objects, easy data transfer between system components

</div><span class="text_page_counter">Trang 95</span><div class="page_container" data-page="95">

Create an abstract Order.

<b>Step 3</b>

Create Buying and Selling command classes.

82

</div><span class="text_page_counter">Trang 97</span><div class="page_container" data-page="97">

Use Broker to receive and process requests.

84

</div><span class="text_page_counter">Trang 98</span><div class="page_container" data-page="98">

<b>a) Singleton pattern</b>

The singleton pattern is a design pattern that ensures that a class has only one instance andit provides a broad way to access that instance. When the single design pattern is espoused, a single instance of a class will appear in the Java virtual machine. To make up for it, a singleton class that conforms to the singleton pattern must provide a global access point. In other words, a single design restricts the number of times a class can be represented. The singleton pattern is used to create active jacks. Maintaining thread pools or buffers also uses it.

Figure 1- 51 singleton pattern

<b>b) Prototype Pattern:</b>

Prototype is a design pattern belonging to the group of Creational Patterns - design patterns for instantiating objects of the class. Prototype specifies the type of objects to be created using a template object, created by copying this template object without making the code dependent on their classes. The Prototype Pattern is used when creating an object is costly and time consuming when you already have a similar object in existence. The Prototype Pattern

85

</div><span class="text_page_counter">Trang 99</span><div class="page_container" data-page="99">

properties if necessary.

Figure 1- 52 Prototype Pattern

<b>c) Compare tables of patterns:</b>

<b>Singleton patternPrototype Pattern</b>

Only 1 Instance of Singleton class is created during the program (only one instance in a class.).Hide class constructor. (The hidden constructor ensures that singleton classes can never be instantiated from outside). The main idea in this model is to make that class responsible for controlling its instantiation (it is initialized only once).

Provides access to the global Object: + Eliminates unnecessary variables, managing only those required by the application. + Singleton will only use a few resources, while global variables are often created from many languages / complex data types, so it consumes more resources.

A class of Singleton type means: it has only a single instance, anywhere can access the instance

Adding and removing concrete classes at run-time: Prototype incorporates the process of instantiating anew object into the system simply by registering a prototype entity with the client. That's a bit more flexible than other building patterns because the client can install and remove prototypes at run-time.Initialize a new object by changing some properties of the object (objects have little difference): A flexible system will let us define a certain action through association with an object ( means a method of a class) rather than defining a new class. The client can perform another action by delegating the prototype class. At the same time, this initialization method also helps us to declare a "new class" without having to program anything. In fact, copying a prototype is like instantiating an object from a new class. Prototype pattern helps to reduce the number of classes that the system needs to use.

86

</div><span class="text_page_counter">Trang 100</span><div class="page_container" data-page="100">

class has only 1 Instance, it is often used for solving problems that need access to applicationssuch as: Shared resource, Logger, Configuration, Thread pool, .. Used in some classes of core java like: java.lang.Runtime, java.awt.Desktop.

Many applications build systems from multiple parts and subsections. The subparts are initialized from many other subparts (subdividing the problem). The prototype pattern also supports this. That is, the parts can be instantiated from copying a prototype from another "struct". As long as the composites all represent Clone() and are used with different constructs as prototypes. But Clone complex objects with circular dependencies (Circular Reference) can be very difficult.

<b>d) The reason for choosing the template for the scenario:</b>

The problem that comes from our scenario is that we use the same resources for a general purpose reading and writing log files, database. And that's also why we use Singleton pattern. Singleton pattern offers many advantages such as anyone can access the singleton class instance, call it anywhere, no need to search FindObjectOfType<T> or GetComponent, etc. The data does not change because there is only one instance. at best, can persist the data after changing the scene (DontDestroyOnLoad(object)). Singleton class supports interface while static class does not, this is the difference that needs to be determined to create a static class or a singleton class. Support inheritance, static class does not support inheritance.

<b>e) Conclusion</b>

Singleton pattern is a very useful pattern. Sometimes you want to make sure that only one instance of a class is instantiated and that your application only uses that instance.Although the Singleton pattern is quite easy to use and useful, we also need to be careful when using it to avoid abuse that makes it difficult to control the code and debug.

After completing this report, we understood and grasped this problem by demonstrating the value of UML diagrams in OOAD and the application of Design Patterns. Moreover, we have applied the student management object-oriented analysis and design to this task to describe the

87

</div><span class="text_page_counter">Trang 101</span><div class="page_container" data-page="101">

demonstrates OOP characteristics and displays in the UML class diagram.

Advanced programming is really great! Thanks to it, we understand how the devices aroundus work. This is very interesting and wonderful. Thankyou our mentor!

88

</div><span class="text_page_counter">Trang 102</span><div class="page_container" data-page="102">

REFERENCES

[1] Design Patterns for Dummies, Steve Holzner, PhD[2] Head First, Eric Freeman

89

</div><span class="text_page_counter">Trang 103</span><div class="page_container" data-page="103">

CRITICAL EVALUATION

Through this post, I think I deserve an M for what I can do. I have completed all requirements both M and P as instructed by the teacher and brief required.

90

</div><span class="text_page_counter">Trang 104</span><div class="page_container" data-page="104">

After completing this report, we understood and grasped this problem by demonstrating the value of UML diagrams in OOAD and the application of Design Patterns. Moreover, we have applied the student management object-oriented analysis and design to this task to describe the characteristics of the object-oriented programming model. This student management program demonstrates OOP characteristics and displays in the UML class diagram.

Advanced programming is really great! Thanks to it, we understand how the devices aroundus work. This is very interesting and wonderful. Thankyou our mentor!

91

</div><span class="text_page_counter">Trang 105</span><div class="page_container" data-page="105">

<b>CRITICAL EVALUATION</b>

After completing this Exercise with our own efforts and with the help of my mentor. During the learning process, he was very dedicated to teaching and always answered our questions. With the knowledge that I have learned, we have presented very fully the questions that Assignment raised in brief, with clear and specific images. Moreover, we are confident that we can self-study and can make the advanced programming process for business.

During the development, we did our best to develop the project successfully. Here is our group review:

- Ability, background knowledge, programming languages to develop projects.

- Have a strong sense of responsibility.

- Encourage participants to finish allocated job on time on a regular basis.

- Afraid to seek assistance from others.- Frequently becoming enraged due to bugs.- Work alone and fully commit to the task at hand.

- Always complete tasks on time and in accordance with the guidelines.

- Products made well, are satisfied and workers of the company and customers.

- Create cooperative relationships to develop later and have better website transactions and products.

- Never stop learning while you're at work.

- Always looking forward to being able to collaborate on new projects with good teams to develop great products together.Also, we have mastered the basics of advanced programming, so we can definitely create a project to help more people connect with each other and make life better!

92

</div><span class="text_page_counter">Trang 106</span><div class="page_container" data-page="106">

3. javatpoint.com (2022). Design Patterns in Java [Online]. Available:

93

</div>

×