Advanced programming (1651), Study Guides, Projects, Research of Advanced Computer Programming

Advanced programming (1651) - Grade D

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 06/15/2023

Phan-Nhat-Linh-11
Phan-Nhat-Linh-11 🇻🇳

4.9

(108)

34 documents

1 / 90

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
12/10/2022
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Phan Nhat Linh
Student ID
GCD201635
Class
GCD0905
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
Linh
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
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a

Partial preview of the text

Download Advanced programming (1651) and more Study Guides, Projects, Research Advanced Computer Programming 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 12 / 10 / 2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Phan Nhat Linh^ Student ID GCD Class GCD0905 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 Linh Grading grid P1 P2 M1 M2 D1 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Table of Contents

  • I/ EXAMINE THE CHARACTERISTICS OF THE OBJECT-ORIENTED PARADIGM AS WELL AS THE VARIOUS CLASS RELATIONSHIPS (P1)
      1. Introduction
      1. What are the characteristics of Object-Oriented programming language?
      1. The various class relationships
  • DIAGRAMS FOR SPECIFIC DESIGN PATTERNS USING A UML TOOL (M1, M2) II/ DETERMINE A DESIGN PATTERN FROM EACH OF THE CREATIONAL, STRUCTURAL AND BEHAVIORAL PATTERN TYPES. DEFINE CLASS
      1. What are Design Patterns in software development?
      1. Creational Design Pattern (Code example in Factory Method Design Pattern)
      1. Structural Design Patterns (Code example in Adapter Design Pattern)
      1. Behavioral Design Patterns (Code example in Strategy Design Pattern)
  • III/ ANALYZE THE RELATIONSHIP BETWEEN THE OBJECT-ORIENTATED PARADIGM AND DESIGN PATTERNS (D1).................................
  • IV/ DESIGN AND BUILD CLASS DIAGRAMS USING A UML TOOL (P2)
      1. Scenario.............................................................................................................................................................................................
      1. Use-case Diagram
      1. Class Diagram and Explanation
      1. Design Pattern: Strategy Design Pattern
  • IV/ DEFINE/REFINE CLASS DIAGRAMS DERIVED FROM A GIVEN CODE SCENARIO USING A UML TOOL (D2)
      1. Class Diagram origin
      1. Class Diagram when use Strategy Design Pattern
  • References
  • Figure 1: C# OOP Table of Figures
  • Figure 2: Class – Object
  • Figure 3: UML of abstraction in C#
  • Figure 4: Example of abstraction in C# (1)
  • Figure 5: Example of abstraction in C# (2)
  • Figure 6: UML of Encapsulation in C#
  • Figure 7: Example of Encapsulation in C#
  • Figure 8: Inheritance
  • Figure 9: UML of Inheritance in C#
  • Figure 10: Example of Inheritance in C# (1)
  • Figure 11: Example of Inheritance in C# (2)
  • Figure 12: UML of polymorphism in C#
  • Figure 13: Example of Polymorphism in C# (1)
  • Figure 14: Example of Polymorphism in C# (2)
  • Figure 15: Example of abstract class in C#
  • Figure 16: Output of the example code above
  • Figure 17: Example of Interfaces in C#
  • Figure 18: Association
  • Figure 19: Example of Association
  • Figure 20: Aggregation
  • Figure 21: Example of Association
  • Figure 22: Composition
  • Figure 23: Example of Composition
  • Figure 24: Inheritance
  • Figure 25: Example of Inheritance
  • Figure 26: Design patterns
  • Figure 27: Factory method Design Patterns (UML)
  • Figure 28: Example of Factory method Design Patterns (UML)
  • Figure 29: Implement Factory method Design Patterns in C# (1)
  • Figure 30: Implement Factory method Design Patterns in C# (2)
  • Figure 31: Singleton Design Patterns (UML)
  • Figure 32: Abstract Factory Design Patterns (UML)
  • Figure 33: Builder Design Patterns (UML)
  • Figure 34: Object Pool Design Patterns (UML)
  • Figure 35: Prototype Design Patterns (UML)
  • Figure 36: Adapter Design Patterns (UML)
  • Figure 37: Implement Adapter Design Patterns in C# (1)
  • Figure 38: Implement Adapter Design Patterns in C# (2)
  • Figure 39: Implement Adapter Design Patterns in C# (3)
  • Figure 40: Bridge Design Pattern (UML)
  • Figure 41: Composite Design Pattern (UML)
  • Figure 42: Decorator Design Pattern (UML)
  • Figure 43: Facade Design Pattern (UML)
  • Figure 44: Flyweight Design Pattern (UML)
  • Figure 45: Proxy Design Pattern (UML)
  • Figure 46: Chain of Responsibility Design Pattern (UML)
  • Figure 47: Command Design Pattern (UML)
  • Figure 48: Interpreter Design Pattern (UML)............................................................................................................................................
  • Figure 49: Iterator Design Pattern (UML)
  • Figure 50: Mediator Design Pattern (UML)
  • Figure 51: Memento Design Pattern (UML)
  • Figure 52: Observer Design Pattern (UML)
  • Figure 53: State Design Pattern (UML)
  • Figure 54: Strategy Design Pattern (UML)
  • Figure 55: Example of Strategy Design Pattern (UML)
  • Figure 56: Implement Strategy Design Pattern in C# (1)
  • Figure 57: : Implement Strategy Design Pattern in C# (2)
  • Figure 58: Template Method Design Pattern (UML)
  • Figure 59: Visitor Design Pattern (UML)
  • Figure 60: The relationship between the object-orientated paradigm and design patterns...................................................................
  • Figure 61: School management
  • Figure 62: Use-case Diagram
  • Figure 63: Class Diagram
  • Figure 64: Strategy Design Pattern in my program
  • Figure 65: Class Diagram origin.................................................................................................................................................................
  • Figure 66: Class Diagram when use Strategy design pattern

2. What are the characteristics of Object-Oriented programming language? 2.1 Object / Class Figure 2 : Class – Object  In object-oriented programming, a class is a blueprint for creating objects (a particular data structure), providing initial values for state (member variables or attributes), and implementations of behavior (member functions or methods).  The user-defined objects are created using the class keyword. The class is a blueprint that defines a nature of a future object. An instance is a specific object created from a particular class. Classes are used to create and manage new objects and support inheritance—a key ingredient in object-oriented programming and a mechanism of reusing code.

 The image above shows how a Car object can be the template for many other Car instances. In the image, there are three instances: polo, mini, and beetle. Here, we will make a new class called Car, that will structure a Car object to contain information about the car’s model, the color, how many passengers it can hold, its speed, etc. A class can define types of operations, or methods, that can be performed on a Car object. For example, the Car class might specify an accelerate method, which would update the speed attribute of the car object. 2.2 Abstraction  Abstraction is one of the key concepts of object-oriented programming (OOP) languages. Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity.  That’s a very generic concept that’s not limited to object-oriented programming. You can find it everywhere in the real world.  Objects in an OOP language provide an abstraction that hides the internal implementation details. Similar to the coffee machine in your kitchen, you just need to know which methods of the object are available to call and which input parameters are needed to trigger a specific operation. But you don’t need to understand how this method is implemented and which kinds of actions it has to perform to create the expected result.  Let’s implement the coffee machine example in Java. You do the same in any other object-oriented programming language. The syntax might be a little bit different, but the general concept is the same. Advantages of Abstraction  The main benefit of using an Abstraction in Programming is that it allows you to group several related classes as siblings.  Abstraction in Object Oriented Programming helps to reduce the complexity of the design and implementation process of software.

Figure 5 : Example of abstraction in C# (2) As the image above we can see that Interface IGradeStrategy has a method RatingGrade() which returns a string but no body. The FailStrategy class has inherited from the IGradeStrategy class and has to write an extra body for the RatingGrade() method. 2.3 Encapsulation  Encapsulation Meaning: In object-oriented computer programming languages, the notion of encapsulation (or OOP Encapsulation) refers to the bundling of data, along with the methods that operate on that data, into a single unit. Many programming languages use encapsulation frequently in the form of classes. A class is a program code-template that allows developers to create an object that has both variables (data) and behaviors (functions or methods). A class is an example of encapsulation in computer science in that it consists of data and methods that have been bundled into a single unit.  Encapsulation may also refer to a mechanism of restricting the direct access to some components of an object, such that users cannot access state values for all of the variables of a particular object. Encapsulation can be used to hide both data members and data functions or methods associated with an instantiated class or object.

UML

Figure 6 : UML of Encapsulation in C#

2.4 Inheritance Figure 8 : Inheritance  Inheritance is one of the core concepts of object-oriented programming (OOP) languages. It is a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods.  You can use it to declare different kinds of exceptions, add custom logic to existing frameworks, and even map your domain model to a database.  Creating a unique class for every single animal would quickly get very repetitious because there are some properties and behaviors that apply to every single animal, from a mouse to an elephant. Shared functions might include feed( ), hydrate( ), cleanEnclosure( ). Instead of creating these shared attributes over and over for every animal, we could instead create a

parent Animal class! This parent class would contain the properties and behaviors universal to all animals and save us from having to create those shared functions ad infinitum. UML: Figure 9 : UML of Inheritance in C#

Figure 11 : Example of Inheritance in C# (2)

The Student class will inherit the Person class as shown in the figure we are seeing. All fields of the Person class such as id, name, age will be inherited by the Student class, in addition to the methods with the virtual keyword so that the subclass can override that method. In the submethod, except for inherited fields, the Student class can have a new field of grade. Methods that the Student class overrides will have the override keyword added. 2.5 Polymorphism The word polymorphism is used in various contexts and describes situations in which something occurs in several different forms. In computer science, it describes the concept that objects of different types can be accessed through the same interface. Each type can provide its own, independent implementation of this interface. It is one of the core concepts of object-oriented programming (OOP). If you’re wondering if an object is polymorphic, you can perform a simple test. If the object successfully passes multiple is-a or instanceof tests, it’s polymorphic. As I’ve described in my post about inheritance, all Java classes extend the class Object. Due to this, all objects in Java are polymorphic because they pass at least two instanceof checks. Different types of polymorphism  Static polymorphism o C#, like many other object-oriented programming languages, allows you to implement multiple methods within the same class that use the same name. That is called method overloading and represents a static form of polymorphism. o The parameter sets have to differ in at least one of the following three criteria:  They need to have a different number of parameters, e.g. one method accepts 2 and another one 3 parameters.  The types of the parameters need to be different, e.g. one method accepts a String and another one a Long.  They need to expect the parameters in a different order, e.g. one method accepts a String and a Long and another one accepts a Long and a String. This kind of overloading is not recommended because it makes the API difficult to understand. o In most cases, each of these overloaded methods provides a different but very similar functionality.