1651 Assignment 1 Pass, Assignments of Information Technology

1651-advanced-Assignment 1 Pass

Typology: Assignments

2022/2023

Uploaded on 07/31/2023

truong-duy-minh-fgw-dn
truong-duy-minh-fgw-dn 🇻🇳

5

(7)

12 documents

1 / 44

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 20: Advanced Programming
Submission date
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Trương Duy Minh
Student ID
GCD210505
Class
GCD1102
Assessor name
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
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
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c

Partial preview of the text

Download 1651 Assignment 1 Pass and more Assignments Information Technology 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Trương Duy Minh Student ID GCD Class GCD1102 Assessor name 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 D

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

  • I. Introduction
  • II. OOP general concepts (P1 + P2)
    • 2.1 General concepts of OOP (P1)
      •  Encapsulation:
      •  Inheritance :
      •  Polymorphism :
      •  Abstraction
    • 2.2 Class relationships (P2)
      •  Association
      •  Aggregation
      •  Composition
  • III. CONCLUSION
  • References
  • Figure 1: OOP TABLE OF FIGURES
  • Figure 2: Class
  • Figure 3: Objects in a class
  • Figure 4: Examples of encapsulation.....................................................................................................................................................................
  • Figure 5: Example of inheritance
  • Figure 6: Example of new keyword
  • Figure 7: Example of sealed
  • Figure 8: Example of polymorphism (code)
  • Figure 9: Example of polymorphism (UML)
  • Figure 10: Abstraction
  • Figure 11: Example of abstraction (code)
  • Figure 12: Example of abstraction (UML)
  • Figure 13: Example of association (code)
  • Figure 14: Example of association (UML)
  • Figure 15: Example of aggregation (code)
  • Figure 16: Example of aggregation (UML)
  • Figure 17: Example of composition (code)
  • Figure 18: Example of composition (UML)

I. Introduction

This report aims to introduce the general concepts of Object-Oriented Programming (OOP) and its characteristics, as well as the different class relationships. Additionally, a scenario will be presented to demonstrate OOP implementation in a practical context through Usecase and Class diagrams.

II. OOP general concepts (P1 + P2)

2.1 General concepts of OOP (P1)

Introduce OOP  Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of objects. It is a popular programming approach that is widely used in software development. OOP emphasizes the use of classes and objects to represent real-world entities and their interactions.  In OOP, the focus is on the data and procedures that manipulate the data, rather than the logic that controls the flow of the program. OOP has several characteristics such as encapsulation, inheritance, polymorphism, and abstraction that make it a powerful and efficient programming approach. Understanding these concepts is essential when designing and developing software applications. OOP also provides different class relationships such as association, aggregation, and composition that help define the relationships between objects. OOP is a widely accepted programming paradigm that provides a modular, scalable, and easy-to-maintain approach to software development.

 Modifiers: A class can be public or internal etc. By default modifier of the class is internal.  Keyword class: A class keyword is used to declare the type class.  Class Identifier: The variable of type class is provided. The identifier (or name of the class) should begin with an initial letter which should be capitalized by convention.  Base class or Super class: The name of the class’s parent (superclass), if any, preceded by the: (colon). This is optional.  Interfaces: A comma-separated list of interfaces implemented by the class, if any, preceded by the: (colon). A class can implement more than one interface. This is optional.  Body: The class body is surrounded by {} (curly braces). Constructors in class are used for initializing new objects. Fields are variables that provide the state of the class and its objects, and methods are used to implement the behavior of the class and its objects.  Objects: It is a basic unit of Object-Oriented Programming and represents real-life entities. A typical C# program creates many objects, which as you know, interact by invoking methods. An object consists of:  State: It is represented by attributes of an object. It also reflects the properties of an object.  Behavior: It is represented by the methods of an object. It also reflects the response of an object with other objects.  Identity: It gives a unique name to an object and enables one object to interact with other objects. Consider Dog as an object and see the below diagram for its identity, state, and behavior. Figure 3 : Objects in a class

Characteristics of OOP:

 Encapsulation:

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In a different way, encapsulation is a protective shield that prevents the data from being accessed by the code outside this shield. (htt73)

Figure 4 : Examples of encapsulation Access modifiers are also known as access specifiers used to preserve the concept of encapsulation of data by specifically restricting the access of variable data using some particular keywords. These are used to specify a specific variable's accessibility or scope and functionality within a C# application. (htt74)  Public Access Modifier is one of the modifiers that allow programmers to expose all of its member variables and methods outside the class scope. Members of a class that are declared as public can be accessed from anywhere within the program.  Protected Access Modifier: is associated with a property or a method where class members can be accessed only by classes (derived classes) inherited from the present class (base class).  Internal Access Modifier : is used to restrict the access entirely to classes distinct within the existing project. In other words, members of a class with internal access specifier can be accessed from other classes or methods specified within the project application.  Protected Internal Access Modifier: allows any class in hiding the member variables and class methods from additional and existing class objects and their associated methods, apart from the child class(es) that are there within the same program or application.

Private Access Modifier : is another access specifier that allows programmers to hide or preserve the member variables and methods from other member functions or class objects. The private members of a class can be accessed by only the functions belonging to the same class.

 Inheritance :

Inheritance allows us to create a new class from an existing class. It is a key feature of Object-Oriented Programming (OOP). The class from which a new class is created is known as the base class (parent or superclass). And, the new class is called derived class (child or subclass) The derived class inherits the fields and methods of the base class. This helps with the code reusability in C#. (htt75)

Figure 5 : Example of inheritance

 Some keywords in inheritance:

1. New

When used as a declaration modifier, the new keyword explicitly hides a member that is inherited from a base class. When you hide an inherited member, the derived version of the member replaces the base class version. This assumes that the base class version of the member is visible, as it would already be hidden if it were marked as private or, in some cases, internal. Although you can hide public or protected members without using the new modifier, you get a compiler warning. If you use new to explicitly hide a member, it suppresses this warning. You can also use the new keyword to create an instance of a type or as a generic type constraint.

Figure 6 : Example of new keyword

2. Virtual

In C#, a virtual method is a method that can be overridden in a derived class. When a method is declared as virtual in a base class, it allows a derived class to provide its own implementation of the method. To declare a method as virtual in C#, the "virtual" keyword is used in the method declaration in the base class. For example: In the derived class, the method can be overridden by using the "override" keyword in the method declaration. For example:

Figure 7 : Example of sealed

 Polymorphism :

Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance lets us inherit fields and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.

Figure 9 : Example of polymorphism (UML) Method overloading and overriding are two common forms of polymorphism (the ability for a method or class to have multiple forms) in C# that are often confused because of their similar sounding names. In this article, we show the difference between the two with some practical code examples. (htt76)  Overloading is the ability to have multiple methods within the same class with the same name, but with different parameters. Each of these methods has their own implementation as well, meaning that they can behave differently depending on what is passed in. Overloading is known as compile-time (or static) polymorphism because each of the different overloaded methods is resolved when the application is compiled. To demonstrate overloading, lets start with a calculator class that doesn't use overloading:

Instead, we could refactor this class to use overloading:  Overriding, on the other hand, is the ability to redefine the implementation of a method in a class that inherits from a parent class. When a method is overridden, the name and the parameters stay the same, but the implementation that gets called depends on the type of the object that's calling it. Overriding is known as runtime (or dynamic) polymorphism because the type of the calling object is not known until runtime, and therefore the method implementation that runs is determined at runtime.