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

higher nationals in computing advanced programming assignment

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 (4.8 MB, 42 trang )

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

<b> Higher Nationals in Computing</b>

<b>Advanced ProgrammingASSIGNMENT 1</b>

<b>Learner’s name: NGUYỄỄN HOÀNG PHƯƠNG ID: GCS200104</b>

<b>Class: GCS0902Subject code: 1651</b>

<b>Assessor name: Nguyễễn Văn Sơn</b>

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

<b>ASSIGNMENT 1 FRONT SHEET</b>

<b>Unit number and title</b> Unit 20: Advanced Programming

<b>submissionRe-submission Date<sup>Date Received 2nd </sup></b>

<b>submission</b>

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

<b>❒</b>

<b>Summative Feedback: </b>

<b>❒</b>

<b>Resubmission Feedback:</b>

<b>Lecturer Signature:</b>

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

<b>ASSIGNMENT 1 BRIEF</b>

<b>Assignment title </b> Examine and design solutions with OOP and Design Patterns

<b>Submission Format:</b>

<b>Format: The submission is in the form of a group written report. This should be written in a concise,</b>

formal business style using single spacing and font size 12. You are required to make use ofheadings, paragraphs and subsections as appropriate, and all work must be supported withresearch and referenced using the Harvard referencing system. Please also provide a bibliographyusing the Harvard referencing system.

Submission Students are compulsory to submit the assignment in due date and in a way requested by theTutors. The form of submission will be a soft copy in PDF posted on corresponding course of

Note: The Assignment must be your own work, and not copied by or from another student or frombooks etc. If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you mustreference your sources, using the Harvard style. Make sure that you know how to reference properly, and thatunderstand the guidelines on plagiarism. If you do not, you definitely get fail

<b>Assignment Brief and Guidance:</b>

<small>Scenario: You have recently joined a software development company to help improve theirdocumentation of their in-houses software libraries which were developed with very poor</small>

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

<small>docu eooeouses so w ebes w cwe e deve oped wve y poodocumentation. As a result, it has been very difficult for the company to utilise their code in multipleprojects due to poor documentation. Your role is to alleviate this situation by showing the efficient ofUML diagrams in OOAD and Design Patterns in usages</small>.

<small>You and your team need to explain characteristics of Object-oriented programming paradigm byapplying Object-oriented analysis and design on a given (assumed) scenario. The scenario can be smallbut should be able to presents various characteristics of OOP (such as: encapsulation, inheritance,polymorphism, override, overload, etc.).</small>

<small>The second task is to introduce some design patterns (including 3 types: creational, structural andbehavioral) to audience by giving real case scenarios, corresponding patterns illustrated by UML classdiagrams. </small>

<small>To summarize, you should analyze the relationship between the object-orientated paradigm and designpatterns.</small>

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

The presentation should be about approximately 20-30 minutes and it should be summarized of the teamreport.

<b>Learning Outcomes and Assessment Criteria</b>

<b>LO1</b> Examine the key components related to the object-orientated programming paradigm, analysing design pattern types

<b>P1 </b>Examine the characteristics of the object-orientated paradigmas well as the various classrelationships.

<b>M1 </b>Determine a design pattern from each of the creational, structural and behavioural pattern types.

<b>D1 </b>Analyse the relationship between the object-orientated paradigm and design patterns.

<b>LO2 </b>Design a series of UML class diagrams

<small>P2 Design and build class diagrams using a UML tool. </small>

<small>M2 Define class diagrams for specific design patterns using a UML tool. </small>

<small>D2 Define/refine class</small>

<small>diagrams derived from a given codescenario using a UML tool. </small>

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

<b>Table of Contents</b>

<b>1.Examine the characteristics of the object-orientated paradigm as well as the various class relationships. (P1)...6</b>

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

<b>1.3.Various Class Relationship...12</b>

<b>2.Design and build class diagrams using a UML tool. (P2)...16</b>

<b>2.2.Usecase diagram...16</b>

<b>2.3.Class diagram...18</b>

<b>Bibliography...20</b>

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

<b>1. Examine the characteristics of the object-orientated paradigm as wellas the various class relationships. (P1)</b>

<b>1.1.What is OOP ? </b>

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

<b>-</b> Object oriented programming (OOP) is a programming structure where programs are organized around objects as opposed to action and logic. This is essentially a design philosophy that uses a different set of programming languages such as C#. Understanding OOP concepts can help make decisions about how you should design an application and what language to use.[ CITATION ALE17 \l 1066 ]

<b>-</b> A simple example would be a class representing a person. The person class would contain attributes to represent information such as the person’s age, name, height, etc. The class definition might also contain functions such as "sayMyName" which would simply print that person’s name to the screen.

<b>-</b> A family could be constructed by instantiating person objects from the class for each member of the family. Each person object would contain different data attributes since each person is unique.

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

<b>1.2.4 Basic concept of OOP</b>

<b>-</b> Object-oriented programming has four basic concepts: encapsulation, abstraction, inheritance, andpolymorphism. Even if these concepts seem incredibly complex, understanding the general

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

framework of how they work will help you understand the basics of an OOP computer program. Below, we outline these four basic principles and what they entail:

+ Encapsulation+ Abstraction+ Inheritance

+ Polymorphism [ CITATION Kyl21 \l 1066 ]

<b>1.2.1. Encapsulation</b>

<b>-</b> The word, “encapsulate,” means to enclose something. Just like a pill "encapsulates" or contains the medication inside of its coating, the principle of encapsulation works in a similar way in OOP:by forming a protective barrier around the information contained within a class from the rest of the code.

<b>-</b> In OOP, we encapsulate by binding the data and functions which operate on that data into a single unit, the class. By doing so, we can hide private details of a class from the outside world and only expose functionality that is important for interfacing with it. When a class does not allow calling code access to its private data directly, we say that it is well encapsulated.

<b>-</b> Example: Elaborating on the person class example from earlier, we might have private data in the class, such as "socialSecurityNumber," that should not be exposed to other objects in the program.By encapsulating this data member as a private variable in the class, outside code would not have direct access to it, and it would remain safe within that person’s object.

<b>-</b> If a method is written in the person class to perform, say, a bank transaction called "bankTransaction()," that function could then access the "socialSecurityNumber" variable as

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

necessary. The person’s private data would be well encapsulated in such a class. [ CITATION Kyl21 \l 1066 ]

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

[ CITATION AKs22 \l 1066 ]

<b>1.2.2. Abstraction.</b>

<b>-</b> Often, it’s easier to reason and design a program when you can separate the interface of a class from its implementation, and focus on the interface. This is akin to treating a system as a “black box,” where it’s not important to understand the gory inner workings in order to reap the benefits of using it.

<b>-</b> This process is called “abstraction” in OOP, because we are abstracting away the gory

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

p , g y g yimplementation details of a class and only presenting a clean and easy-to-use interface via the class’ member functions. Carefully used, abstraction helps isolate the impact of changes made to the code, so that if something goes wrong, the change will only affect the implementation details of a class and not the outside code.

<b>-</b> Example: Think of a stereo system as an object with a complex logic board on the inside. It has buttons on the outside to allow for interaction with the object. When you press any of the buttons, you're not thinking about what happens on the inside because you can't see it. Even though you

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

can't see the logic board completing these functions as a result of pressing a button, it's still performing them., albeit hidden to you.

<b>-</b> This is the concept of abstraction, which is incredibly useful in all areas of engineering and also applied to great effect in object-oriented programming.

<b>-</b> Example: In OOP, we might have a class defined to represent the human body. One might define some functions as part of its publicly facing interface such as “walk()” or “eatFood().” Calling code could call these functions and remain completely oblivious to the complex inner workings ofthe human body and its necessary functions to perform the act of walking or eating. These details are completely hidden in the implementation of the walk() and eatFood() body functions and are, therefore, us abstracted away from the end user. In these cases, it’s not important for calling code to understand how the brain coordinates walking or how the stomach manages digesting the food, but rather simply that a human walked or ate. [ CITATION Kyl21 \l 1066 ]

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

[ CITATION Vik18 \l 1066 ]

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

<b>1.2.3. Inheritance</b>

<b>-</b> Object-oriented languages that support classes almost always support the notion of “inheritance.” Classes can be organized into hierarchies, where a class might have one or more parent or child classes. If a class has a parent class, we say it is derived or inherited from the parent class and it represents an “IS-A” type relationship. That is to say, the child class “IS-A” type of the parent class.

<b>-</b> Therefore, if a class inherits from another class, it automatically obtains a lot of the same functionality and properties from that class and can be extended to contain separate code and data.A nice feature of inheritance is that it often leads to good code reuse since a parent class’ functionsdon’t need to be re-defined in any of its child classes.

<b>-</b> Consider two classes: one being the superclass—or parent—and the other being the subclass—or child. The child class will inherit the properties of the parent class, possibly modifying or extending its behavior. Programmers applying the technique of inheritance arrange these classes into what is called an “IS-A” type of relationship.

<b>-</b> Example: For instance, in the animal world, an insect could be represented by an Insect superclass. All insects share similar properties, such as having six legs and an exoskeleton. Subclasses might be defined for grasshoppers and ants. Because they inherit or are derived from the Insect class, they automatically share all insect properties. [ CITATION Kyl21 \l 1066 ]

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

[ CITATION Ris20 \l 1066 ]

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

<b>1.2.4. Polymorphism</b>

<b>-</b> In OOP, polymorphism allows for the uniform treatment of classes in a hierarchy. Therefore, calling code only needs to be written to handle objects from the root of the hierarchy, and any object instantiated by any child class in the hierarchy will be handled in the same way.

<b>-</b> Because derived objects share the same interface as their parents, the calling code can call any function in that class’ interface. At run-time, the appropriate function will be called depending on the type of object passed leading to possibly different behaviors.

<b>-</b> Example: Suppose we have a class called, “Animal” and two child classes, “Cat,” and “Dog.” If the Animal class has a method to make a noise, called, “makeNoise,” then, we can override the "makeNoise" function that is inherited by the sub-classes, "Cat" and "Dog," to be “meow” and “bark,” respectively. Another function can, then, be written that accepts any Animal object as a parameter and invokes its "makeNoise" member function. The noise will be different: either a “meow” or a “bark” depending on the type of animal object that was actually passed to the function. [ CITATION Kyl21 \l 1066 ]

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

[ CITATION San20 \l 1066 ]

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

<b>1.3.Various Class Relationship</b>

<b>-</b> Classes are interrelated to each other in specific ways. In particular, relationships in class diagrams include different types of logical connections. The following are such types of logical connections that are possible in UML:

+ Association+ Directed Association+ Reflexive Association+ Multiplicity + Aggregation+ Composition+ Realization

+ Inheritance/Generalization

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

<b>-Association</b>: is a broad term that encompasses just about any logical connection or relationship between classes. For example, passenger and airline may be linked as above.

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

For example, a staff member working in an airport may be a pilot, aviation engineer, a ticket dispatcher, a guard, or a maintenance crew member. If the maintenance crew member is managed by the aviation engineer there could be a managed by relationship in two instances of the same class.

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

<b>-Multiplicity: </b>is the active logical association when the cardinality of a class in relation to another is being depicted. For example, one fleet may include multiple airplanes, while one commercial airplane may contain zero to many passengers. The notation 0..* in the diagram means “zero to many”.

<b>-Aggregation: </b>refers to the formation of a particular class as a result of one class being aggregatedor built as a collection. For example, the class “library” is made up of one or more books, among other materials. In aggregation, the contained classes are not strongly dependent on the lifecycle of the container. In the same example, books will remain so even when the library is dissolved. Toshow aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class. To show aggregation in a diagram, draw a line from the parent class to the child class with a diamond shape near the parent class.

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

<b>--Composition</b>: The composition relationship is very similar to the aggregation relationship. with the only difference being its key purpose of emphasizing the dependence of the contained class to the life cycle of the container class. That is, the contained class will be obliterated when the container class is destroyed. For example, a shoulder bag’s side pocket will also cease to exist once the shoulder bag is destroyed. To show a composition relationship in a UML diagram, use a directional line connecting the two classes, with a filled diamond shape adjacent to the containerclass and the directional arrow to the contained class.

<b>--Inheritance / Generalization: </b>refers to a type of relationship wherein one associated class is a child of another by virtue of assuming the same functionalities of the parent class. In other words, the child class is a specific type of the parent class. To show inheritance in a UML diagram,a solid line from the child class to the parent class is drawn using an unfilled arrowhead.

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

<b>--Realization:</b> denotes the implementation of the functionality defined in one class by another class. To show the relationship in UML, a broken line with an unfilled solid arrowhead is drawn from the class that defines the functionality of the class that implements the function. In the example, the printing preferences that are set using the printer setup interface are being implemented by the printer.

<b>2. Design and build class diagrams using a UML tool. (P2)2.1.Scenario</b>

<b>-</b> The University of Greenwich is expanding, so the management of staff and students is becoming more and more complicated. We need to create a software that can manage students and staff inthe school. The application allows to manage students, students' grades, staff management, staff salaries.

</div>

×