1. Trang chủ
  2. » Luận Văn - Báo Cáo

higher nationals in computing advanced programming assignment

42 0 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Tiêu đề Advanced Programming Assignment
Tác giả Nguyen Hoang Phuong
Người hướng dẫn Nguyen Van Son
Trường học BTEC
Chuyên ngành Computing
Thể loại assignment
Định dạng
Số trang 42
Dung lượng 4,8 MB

Cấu trúc

  • 1.1. What is OOP ? (12)
    • 1.2.1. Encapsulation (15)
    • 1.2.3. Inheritance (21)
    • 1.2.4. Polymorphism (23)
  • 1.3. Various Class Relationship (25)
  • 2. Design and build class diagrams using a UML tool. (P2) (33)
    • 2.1. Scenario (33)
    • 2.2. Usecase diagram (34)
    • 2.3. Class diagram (37)

Nội dung

The presentation should be about approximately 20-30 minutes and it should be summarized of the teamreport.Learning Outcomes and Assessment CriteriaLO1 Examine the key components related

What is OOP ?

Encapsulation

- 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.

- 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.

- 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.

- 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 necessary The person’s private data would be well encapsulated in such a class [ CITATION Kyl21 \l 1066 ]

- 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.

- This process is called “abstraction” in OOP, because we are abstracting away the gory p , g y g y implementation 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.

- 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 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.

- 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

- 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 of the 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 ]

Inheritance

- 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.

- 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’ functions don’t need to be re-defined in any of its child classes.

- 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.

- 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 ]

Polymorphism

- 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.

- 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.

- 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 ]

Various Class Relationship

- 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: 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.

- Directed Association: refers to a directional relationship represented by a line with an arrowhead The arrowhead depicts a container-contained directional flow.

- Reflexive Association: This occurs when a class may have multiple functions or responsibilities

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.

- Multiplicity: 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”.

- Aggregation: refers to the formation of a particular class as a result of one class being aggregated or 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 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 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.

- Composition: 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 container class and the directional arrow to the contained class.

- Inheritance / Generalization: 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.

- Realization: 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.

Design and build class diagrams using a UML tool (P2)

Scenario

- 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 in the school The application allows to manage students, students' grades, staff management, staff salaries.

Usecase diagram

- This is use-case diagram:

- This software has 2 main users: teachers and administrators Teachers can only add students, edit information for students and enter students' grades, teachers do not have the right to delete students Administrators can add, remove, edit teachers, add students, edit and delete students Administrators can also add new subjects and delete new subjects

Class diagram

- Concept are displayed in diagram:

+ Person class is parent class of Student class and Teacher class That is Inheritance in Object Oriented Programming.

+ Student class is used to store student information and Teacher class is used to store Teacher information

+ Student class and Teacher class overriding method showInfo() of Person class That is Polymorphism in Object oriented Programming.

+ Subject class is used to store Subject information

+ Student Grade class is used to store student’s grade

ALTVATER, A., 2017 OOP Concepts in C#: Code Examples and How to Create a Class [Online] Available at: https://stackify.com/oop-concepts-c-sharp/#:~:text=Object%20oriented%20programming

%20(OOP)%20is,programming%20languages%20such%20as%20C%23.

Herrity, K., 2021 What Is Object-Oriented Programming? The Four Basic Concepts of OOP [Online] Available at: https://www.indeed.com/career-advice/career-development/what-is-object-oriented- programming#:~:text=The%20four%20basics%20of%20object,abstraction%2C%20inheritance%2C

Raut, A., 2022 Encapsulation in Object Oriented Programming [Online]

Available at: https://akshayraut.medium.com/encapsulation-in-object-oriented-programming-

Kukurba, V., 2018 JavaScript ES7 OOP Abstraction Class #1 [Online]

Available at: https://www.youtube.com/watch?vSCCQPBqP0

Sidhu, R., 2020 How to Code Inheritance in Java — Beginner’s Tutorial in OOP [Online]

Available at: https://towardsdatascience.com/how-to-code-inheritance-in-java-beginners-tutorial-in-oop- d0fc0a71be98

Sanjay, 2020 Polymorphism in C# NET (OOP Concept) – Detailed Explanation [Online]

Available at: https://procodeguide.com/programming/oop-concept-polymorphism-in-c-net/

Ngày đăng: 08/05/2024, 14:39