ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc, Essays (university) of Programming for Engineers

ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc

Typology: Essays (university)

2021/2022

Uploaded on 07/15/2022

quoc-vo-minh
quoc-vo-minh 🇻🇳

4.8

(13)

14 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 20: Advanced Programming
Submission date
21/06/2022
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Võ Minh Quốc
Student ID
GCD201870
Class
GCD0904
Assessor name
Pham Thanh Son
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
quoc
Grading grid
P1
P2
M1
M2
D1
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download ASSIGNMENT ONE - Advanced Programming (P) - Vo Minh Quoc and more Essays (university) Programming for Engineers in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 20 : Advanced Programming Submission date 21 /06/2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Võ Minh Quốc Student ID GCD Class GCD0904 Assessor name Pham Thanh Son 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 quoc Grading grid P1 P2 M1 M2 D1 D 2

r Summative Feedback: r Resubmission Feedback:

Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date:

Chapter 1 - Introduction:

Applying object-oriented research and design to a specific situation will allow me to define the characteristics of the object-oriented programming paradigm. Even if the situation is not urgent, specific OOP qualities need to be addressed. The audience will be given an explanation of various design trends using real-world case studies and UML class diagrams that reflect the trends. Below you may view my work. Both "Data Abstraction" and "Object-Oriented Programming" have become overused buzzwords. Unfortunately, opinions on what they mean vary. I will discuss numerous class interactions as well as attributes of object-oriented programming, such as encapsulation, inheritance, polymorphism, and others, in this assignment. Then, depending on a specific code scenario, I'll draw a class diagram.

Chapter 2 - OOP general concepts:

1. OOP:

A. Definition OOP is an approach to programming that recognizes life as we know it as a collection of objects that work together to solve a particular problem at hand. The primary object to know about OOP is encapsulation, which is the idea that each object that holds the program is self-sustainable. All the components that make up the object are within the object itself. Since each module within this paradigm is self-sustainable, objects can be taken from one program and used to resolve another problem at hand with little or no alterations. (Saini, 2021) B. Structure of OOP: Class: is an abstract blueprint used to create more concrete objects. Classes often represent broad categories, such as Worker or Employee sharing properties. These classes define the properties that an instance of this type will have, such as running the same program together, but not the value of those properties for a particular object. Classes can also contain functions called methods available only for those types of objects. This function is defined in the class and does some valuable operations for the tool to type the object. (Saini, 2021)

Figure 1. Class Object: Objects are instances of a class that are formed with specified data. Items can be real-world objects or abstract entities. When a class is first formed, the description is the sole object specified. (Saini, 2021) Figure 2. Object Class members:

  • Methods: Methods are functions specified within a class that explain an object's actions. Every method in a class definition begins with a reference to an instance object. In addition, the subroutines included within an object are referred to as instance methods. Methods are used by programmers to ensure reusability or to keep functionality contained to a single object at a time. (Saini, 2021) Figure 3. Method Method Class

Figure 6. Access modifiers

  • Property: A property is similar to a variable and a method in that it has two methods: get and set: Figure 7. Property. C. OOP characteristics:

Encapsulation: This notion allows objects' actions or states to be kept private inside a defined border or class. Other objects will not have direct access to these states; instead, they will only be able to communicate with the object using the methods given. This capability ensures data security for big programs and prevents data tampering from outside sources. Explanation: The 'sound' variable is encapsulated by private, used in the 'Animal' class. In the Main function, to print out the Sound, but we cannot use the 'sound' variable in the 'Animal' class for the 'Program' class, we use 'get' and 'set' to create a Sound property and use 'get' to get sound and switch to Sound. The run variable is encapsulated by private, used in the Animal class. In the Main function, to print out Run. but we cannot use the 'run' variable in the Animal class to the 'Program' class, we use 'get' and set' to create a Run property. Use 'get' to get run and switch to Run. Inheritance: Objects in OOP are frequently quite similar, having shared logic but not exactly the same. As a result, this technique allows us to reuse common logic and isolate it into a different class. This means that the programmer will build a class (child) and derive from another (parent) class, resulting in a hierarchy. This OOP feature requires programmers to conduct more comprehensive data Figure 8. Example of encapsulation

Override: This works by allowing the children's class to override the method with the same name and parameters as the parent class. This override method is frequently used when a developer wants the object to utilize a rewritten version of a method from the parent class. (Saini, 2021) Overload: This feature allows a class to have many methods with similar names, the only difference being that they have distinct parameters, which means the type of data they receive is different. (Saini,

Explanation: We have 2 classes, class 'Animal' and class 'Dog'. In there, class 'Dog' inherits from the 'Animal' class. But the special thing here is the keyword 'virtual'-'override'. The function of this keyword allows the Dog class to inherit or modify information inside the Sound and 'Action' methods from the 'Animal' class. (Saini, 2021) Figure 10. Example of Polymorphism

Abstraction: This notion is seen to be a natural extension of the packing principle. It alleviates the burden of maintaining a vast code base when objects must interact often (especially large objects). In other words, this approach will conceal internal implementation details, making it easier for developers to make adjustments and improvements in the future. (Saini, 2021) Explanation: In the abstract class Animal, includes the methods ‘animalSound’ and ‘animalAction’. Therefore, when class Dog must fully inherit the methods in abstract Animal. Abstract class features:

  • An abstract class can inherit from a class and one or more interfaces.
  • An abstract class can implement code with non-Abstract methods. Figure 11. Example of Abstraction

Essentially, OOP is a method of programming that focuses on objects rather than essential logic rules. This procedure is ideal for big programs with several entities and is continually updated. OOP also provides various additional advantages, such as code reuse, scalability, and efficiency. However, OOP has been criticized for a variety of reasons, one of which is that it overemphasizes the data component of software development and does not place enough emphasis on computation or algorithms. Furthermore, OOP will be more difficult to design and take longer to compile. (Saini, 2021)

2. The class diagram relationships:

Because class diagrams are the foundation of object-oriented modelling, it is critical to comprehend the numerous class diagram relationships and how they affect our solution. Classes are linked to one another in certain ways. Relationships in class diagrams, in particular, encompass several sorts of logical linkages. In UML, the following sorts of logical linkages are possible: A. Association: Association is a wide phrase that refers to any logical link or interaction between classes. As an example, passenger and airline might be linked as seen above. (Nishadha, 2022) Figure 13. Association B. Directed association: A directed relationship is indicated as a line with an arrowhead in Directed Association. The arrowhead represents a directed flow enclosed within a container. (Nishadha, 2022)

Figure 14. Directed association C. Reflexive association: When a class has several functions or responsibilities, this occurs. A pilot, aviation engineer, ticket dispatcher, guard, or maintenance crew member are all examples of airport employees. If the aviation engineer manages the maintenance crew member, there might be a managed by relationship between two instances of the same class. (Nishadha, 2022) Figure 15. Reflexive association D. Multiplicity: When depicting the cardinality of one class in respect to another, the active logical relationship is multiplicity. For example, a fleet may consist of several airplanes, yet a commercial airliner may carry zero to many people. In the graphic, the notation 0..* denotes "zero to many." (Nishadha, 2022) Figure 16. Multiplicity E. Aggregation:

G. Inheritance/Generalization: Inheritance / Generalization refers to a sort of connection in which one connected class is a child of another by virtue of adopting the parent class's functions. To put it another way, the kid class is a subset of the parent class. In order to depict inheritance in a UML diagram, an empty arrowhead is used to create a solid line from the child class to the parent class. (Nishadha, 2022) Figure 19. Inheritance/Generalization H. Realization: The implementation of functionality described in one class by another class is referred to as realization. In UML, a broken line with an empty solid arrowhead is drawn from the class that specifies the functionality to the class that implements the function to demonstrate the connection. The printing options made via the printer setup interface are implemented by the printer in this example. (Nishadha,

Figure 20. Realization

Chapter 3 - OOP scenario

1. Encapsulation:

A. Scenario:

To demonstrate the use of encapsulation, suppose I created an application that allows me to construct a new person profile based on their name and age. An employee class that inherits the person class and extends it with additional properties and methods. I'll use different access modifiers in the classes to allow objects to access only the parts of the class that I want them to and conceal the rest. Class diagram: B. Class diagram: Explain: There are two classes: the person class (parent class) and the employee class (children class). Name, Age and Id, which are kept private, are properties of person class, and it has the function ShowInfo(). The employee class has the same properties and methods as the Person class, but it is added a new property which is branch, and an extra method which is ShowBranch(). Explain: There are two classes: the person class (parent class) and the employee class (children class). Name, Age and Id, which are kept public, are properties of person class, and it has the function ShowInfo(). The employee class has the same properties and methods as the Person class, but it is added a new property which is branch, and an extra method which is ShowBranch().

This is the result when running this small program. It is the fact that this object can access these from a program class that is outside the class for which this attribute was created, as well as the result, which shows that we can access the attribute's value through its property, demonstrate that the public modifier permits all objects outside of the class to access the property. Protected Two properties are kept protected Since two above properties are kept protected, those cannot be accessed through the created object of class Person Private Two properties are kept private Since two above properties are kept private, those cannot be accessed through the created object of class Person Internal Two properties are kept internal Since two about properties are kept internal, those can be accessed through the created object of class Person

2. Abstraction:

A. Scenario: I will create Shape class as an abstract class to build an abstract where all of the other derived shape classes may receive their own area. They will utilize the same method, but with various implementations, according to the abstract method. B. Class diagram: This is the class diagram of Shape which is abstract class with the abstract function area(), and Square which is the class inheriting from Shape class, and it is added the side field and the function area overriding from Shape class. Code: Explain: This is the Shape abstract class with the abstract method area() without logic inside. Explain: This is the Square class has the side field, with constructor, Square class inheriting the function area() from Shape abstract class, and this function is added the logic inside.