1. Trang chủ
  2. » Công Nghệ Thông Tin

1651 assignment 2 (pass)

65 48 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 65
Dung lượng 1,8 MB

Nội dung

1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) 1651 assignment 2 (pass) FPT Greenwich

Higher Nationals in Computing Unit 19: ASSIGNMENT Advanced Programming (1651) Assessor name: LE NGOC THANH Learner’s name: Đào Vĩnh Khang ID: GCS200222 Class: GCS0905B Subject code: 1651 Assignment due: Assignment submitted: ASSIGNMENT FRONT SHEET Qualification BTEC Level HND Diploma in Computing Unit number and title Unit 20: Advanced Programming Submission date 14-02-2022 Date Received 1st submission Re-submission Date 14-02-2022 Date Received 2nd submission Student Name DAO VINH KHANG Student ID GCS200222 Class GCS0905B Assessor name LE NGOC THANH 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 P1 P2 M1 M2 D1 D2 KHANG ❒ Summative Feedback: Grade: Signature & Date: ❒ Resubmission Feedback: Assessor Signature: Date: ASSIGNMENT BRIEF Qualification BTEC Level HND Diploma in Business Unit number Unit 20: Advanced Programming Assignment title Examine and design solutions with OOP and Design Patterns Academic Year 2021 - 2022 Unit Tutor LE NGOC THANH Issue date 28 November 2022 Submission date IV name and date Submission Format: Format: The submission is in the form of a group written report This should be written in a concise, formal business style using single spacing and font size 12 You are required to make use of headings, paragraphs and subsections as appropriate, and all work must be supported with research and referenced 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/ 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 not, you definitely get fail Assignment Brief and Guidance: Scenario: You have recently joined a software development company to help improve their documentation of their in-houses software libraries which were developed with very poor documentation As a result, it has been very difficult for the company to utilise their code in multiple projects due to poor documentation Your role is to alleviate this situation by showing the efficient of UML diagrams in OOAD and Design Patterns in usages Tasks You and your team need to explain characteristics of Object-oriented programming paradigm by applying Object-oriented analysis and design on a given (assumed) scenario The scenario can be small but should be able to presents various characteristics of OOP (such as: encapsulation, inheritance, polymorphism, override, overload, etc.) The second task is to introduce some design patterns (including types: creational, structural and behavioral) to audience by giving real case scenarios, corresponding patterns illustrated by UML class diagrams Learning Outcomes and Assessment Criteria Pass Merit Distinction LO1 Examine the key components related to the object-orientated programming paradigm, analysing design pattern types P3 Build an application M1 Determine a design pattern D1 Analyse the relationship derived from UML class from each of the creational, between the object-orientated structural and behavioural pattern paradigm and design patterns diagrams types LO2 Design a series of UML class diagrams P4 Discuss a range of design patterns with relevant examples of creational, structural M2 Define class diagrams for specific design patterns using a UML tool D2 Define/refine class diagrams derived from a given code scenario using a UML tool Table of contents Contents ASSIGNMENT FRONT SHEET ASSIGNMENT BRIEF Table of contents I Introduction 1 Characteristics of the object-orientated paradigm - Abstraction: - Inheritance: - Polymorphism : - Abstract classes - Interfaces: 10 Coding Managing School System: 11 What is design pattern 34 When use design patterns 35 Categorization of patterns 35 3.1Creational Pattern 37 3.2 Structure Patterns 43 3.3 Behavior Patterns 52 I Introduction Based on the class diagram created in assignment 1, in this assignment I will build an application derived from that UML class diagram Then, I will cover a series of design patterns with relevant examples of creative, structural, and behavioral patterns My report includes two parts: ÷ Build an application derived from UML class diagram ÷ Design patterns II Build an application derived from UML class diagrams Characteristics of the object-orientated paradigm - Object/Class: Explanation: - Here you can see the Object class at the top of the type hierarchy Type and Type are reference types Class inherits the Object class while Class inherits it directly using Class Struct1 is a value type that implicitly inherits the Object class through the System.ValueType type Result: - - Abstraction: - If you observe the above code, we defined a Shape class with required fields, properties, and methods with the public, private access modifiers to achieve an abstraction functionality by hiding and exposing some of the methods and properties based on our requirements - Here, the public modifier allows defined fields, properties, and methods to access outside of the class The private modifier is used to hide or restrict access to required fields, properties, and methods outside of class - By creating an instance of the Shape class, we can access defined fields, properties, and methods - Result: - Encapsulation: Explanation: Also known as Wrapper Definition: The Adapter pattern is used to translate the interface of one class into another interface A class adapter uses multiple inheritance (by extending one class and/or implementing one or more classes) to adapt one interface to another An object adapter relies on object aggregation When to use: ÷ When you want to use an existing class, and its interface does not match the one you need ÷ When you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that not necessarily have compatible interfaces ÷ When you want to increase transparency of classes ÷ When you want to make a pluggable kit Benefits: ÷ It helps in reducing the code redundancy by providing the variation of the object predeveloped ÷ It provides easier access to variations of objects using the adapter class methods ÷ The memory utilization is reduced as the processing necessary to create the variation of objects is reduced ÷ It improves the maintainability of the code It becomes easier to edit the variations of the objects ÷ Reduced development time due to already manipulated objects available from the adapter class 45 3.2.2 Bridge Pattern Definition: Decouple an abstraction or interface from its implementation so that the two can vary independently Bridge makes a clear-cut between abstraction and implementation When to use: ÷ When you want to separate the abstract structure and its concrete implementation ÷ When you want to share an implementation among multiple objects, when you want to reuse existing resources in an 'easy to extend' fashion ÷ When you want to hide implementation details from clients Changes in implementation should have no impact on clients Benefits: Implementation can be selected or switched at run-time The abstraction and implementation can be independently extended or composed 46 3.2.3 Composite Pattern Definition: The Composite pattern helps you to create tree structures of objects without the need to force clients to differentiate between branches and leaves regarding usage The Composite pattern lets clients treat individual objects and compositions of objects uniformly Where to use ÷ When you want to represent a part-whole relationship in a tree structure ÷ When you want clients to be able to ignore the differences between compositions of objects and individual objects ÷ When the structure can have any level of complexity and is dynamic Benefits ÷ Define class hierarchies consisting of primitive objects and composite objects ÷ Makes it easier to add new kind of components 47 3.2.4 Decorator Pattern Definition: The Decorator pattern lets you attach additional responsibilities and modify an instance functionality dynamically Decorators provide a flexible alternative to subclassing for extending functionality, using composition instead of inheritance Where to use ÷ When you want to add responsibilities to individual objects dynamically and transparently, without affecting the original object or other objects ÷ When you want to add responsibilities to the object that you might want to change in the future ÷ When extension by static subclassing is impractical Benefits ÷ More flexibility than static inheritance ÷ Avoids feature-laden classes high up in the hierarchy ÷ Simplifies coding because you write a series of classes each targeted at a specific part of the functionality rather than coding all behavior into the object ÷ Enhances the object's extensibility because you make changes by coding new classes 48 III.1.5 Flyweight Pattern Definition Flyweight pattern provides a mechanism by which you can avoid creating a large number of 'expensive' objects and instead reuse existing instances to represent new ones Where to use ÷ When there is a very large number of objects that may not fit in memory ÷ When most of an object9s state can be stored on disk or calculated at runtime ÷ When there are groups of objects that share state ÷ When the remaining state can be factored into a much smaller number of objects with shared state Benefits Reduce the number of objects created, decrease memory footprint and increase performance ø Example of Structure pattern Here, I will take the example of adapter pattern First, I will create interfaces for CreditCard Then, I will create a BankDetails class 49 Next, I will create BankCustomer which extends BankDetails and implement CreditCard class 50 Finally, I will create AdapterPatternDemo to run the program 51 When AdapterPatternDemo is executed, the result is: 3.3Behavior Patterns Whereas creational design patterns have to with instantiating objects and structural patterns have to with composing objects and classes into larger, more complex structures, behavioral design patterns are concerned with communication among a family of objects While there are a variety of behavioral design patterns, we will consider four here: chain of responsibility, observer, state, strategy and command pattern 3.3.1 Chain-of-responsibility Pattern Definition: The Chain-of-responsibility pattern lets more than one object handle a request without mutual knowledge We avoid coupling between the sender of a request and the possible receivers We place all receivers in a chain which lets the receiving objects pass the request along to the next receiver in the chain until one receiver handles it, or the end of the chain is reached When to use ÷ When more than one object may handle a request, and the handler isn't known ÷ When you want to issue a request to one of several objects without specifying the receiver explicitly 52 ÷ When theset of objects that can handle a request should be specified dynamically Benefits ÷ It reduces coupling ÷ It increases the flexibility of handling a request 3.3.2 Command Pattern Definition The Command pattern is used to create objects that represents actions and events in an application A command object encapsulates an action or event and contains all information required to understand exactly what has happened By passing the command object as a parameter we can, anywhere needed extract information about occurred actions and events When to use ÷ Where you want an action that can be represented in many ways, like drop-down menu, buttons and popup menu ÷ To create undo/redo functionality Benefits ÷ A command object is a possible storage for procedure parameters It can be used while assembling the parameters for a function call and allows the command to be set aside for later use ÷ A class is a suitable place to collect code and data related to a specific action or event ÷ It allows the reaction to a command to be executed sometime after it has occurred ÷ Command objects enables data structures containing multiple commands ÷ Command objects supports undo-able operations, provided that the command objects are stored (for example in a linked list) 53 3.3.3 Observer Pattern Definition: An observer is a structural pattern that enables publish/subscribe functionality This is accomplished by an autonomous object, publisher that allows other objects to attach or detach their subscription as they like The pattern does not impose any limit to the number of observers that can attach, or subscribe, themselves for notification on future changes in the publisher's state When to use When an object wants to publish information and many objects will need to receive that Benefits Makes for a loose coupling between publisher and subscriber as the publisher does not need to know who or how many subscribers there will be 3.3.4 State Pattern Definition: The State pattern allows an object to alter its behavior when its internal state changes By using inheritance and letting subclasses represent different states and functionality we can switch during runtime This is a clean way for an object to partially change its type at runtime When to use ÷ When we need to define a "context" class to present a single interface to the outside world By defining a State abstract base class ÷ When we want to represent different "states" of a state machine as derived classes of the State base class 54 Benefits ÷ Cleaner code when each state is a class instead ÷ Use a class to represent a state, not a constant 3.3.5 Strategy Pattern Definition: Use strategy when you need to define a family of algorithms, encapsulate each one, and make them interchangeable Strategy lets the algorithm vary independently from clients that use it Related patterns include State, Flyweight, Decorator, Composite Where to use ÷ When you need to use one of several algorithms dynamically ÷ When you want to configure a class with one of many related classes (behaviors) ÷ When an algorithm uses data that clients should not know about Benefits ÷ Reduces multiple conditional statements in a client ÷ Hides complex, algorithmic-specific data from the client ÷ Provides an alternative to subclassing ÷ Can be used to hide data that an algorithm uses that client should not know about ø Example of behavior pattern Here, I will take the example of command pattern 55 56 When executing TestCommand the result is: 57 IV.Conclusion This assignment described how some of the key data technologies work and provided guidance on how to use them properly We covered technologies for student management, data access, data processing, and data publishing on the web We have also focused on writing computer languages We looked at the advantages and disadvantages of different storage options, we looked at how to design efficient data storage, and we discussed how to write good computer code There are several important ideas to draw from this assignment One of them is that the computer is a very versatile and powerful tool, and it is a tool that we can control Files and documents, especially those in open standard formats, can be manipulated by many software tools, not just one specific piece of software A programming language is a tool that allows us to manipulate data stored in files and manipulate data stored in RAM in unlimited ways Even with basic knowledge of programming, we can a lot of data processing tasks A related idea is that computer code is the preferred approach for communicating our instructions to computers This approach allows us to be precise and expressive, it provides a complete record of our actions, and it allows others to copy our work Writing computer code to process, store, or display data is a task that needs to be done with considerable discipline It's important to develop code in small pieces and in careful stages, and produce code that's neatly and logically structured This discipline is required to write code that will produce correct results both now and in the future Another important idea is the DRY principle Information, whether data or computer code, should be organized so that there is only one copy of each significant unit of information We see this idea most clearly in terms of data storage, in XML document design, and in relational database design But the idea of effectively organizing information can affect the way we work in many ways The DRY principle can also be applied to the way we write computer code, especially in the use of loops and functions It can also be applied to how we collect our code in files and how we organize files in folders or folders In summary, in this assignment I have built an application derived from the UML class diagram generated in assignment Then, I explained a series of design patterns with relevant examples of types pattern of creation, structure and behavior 58 References GeeksforGeeks 2020 C# | Object Class - Geeksforgeeks [online] Available at: < https://www.geeksforgeeks.org/c-sharp-object-class/ > [Accessed 12 Dec 2022] GeeksforGeeks 2020 C# | Abstraction - Geeksforgeeks [online] Available at: < https://www.geeksforgeeks.org/c-sharp-abstraction/ > [Accessed 12 Dec 2022] GeeksforGeeks 2020 C# | Encapsulation - Geeksforgeeks [online] Available at: < https://www.geeksforgeeks.org/c-sharp-encapsulation/ > [Accessed 12 Dec 2022] GeeksforGeeks 2020 C# | Inheritance - Geeksforgeeks [online] Available at: < https://www.geeksforgeeks.org/c-sharp-inheritance/ > [Accessed 12 Dec 2022] W3schools.com 2020 C# Polymorphism [online] Available at: < https://www.w3schools.com/cs/cs_polymorphism.asp > [Accessed 12 Dec 2022] GeeksforGeeks 2020 C# | Abstract Classes - Geeksforgeeks [online] Available at: < https://www.geeksforgeeks.org/c-sharp-abstract-classes/ > [Accessed 12 Dec 2022] W3schools.com 2020 C# Interface [online] Available https://www.w3schools.com/cs/cs_interface.asp > [Accessed 12 Dec 2022] 59 at: <

Ngày đăng: 18/07/2023, 23:51

TỪ KHÓA LIÊN QUAN

w