















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Advanced Programming - 1651 - Pass. Game is so easy!!!
Typology: Study Guides, Projects, Research
1 / 55
This page cannot be seen from the preview
Don't miss anything!
















































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 Student ID Class 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
Grade: Assessor Signature: Date: Lecturer Signature:
Tasks You and your team need to explain characteristics of Object-oriented programming paradigm by applying Object-oriented analysis and design on a given (assumed) scenario. The scenario can be small but should be able to presents various characteristics of OOP (such as: encapsulation, inheritance, polymorphism, override, overload, etc.). The second task is to introduce some design patterns (including 3 types: creational, structural and behavioral) to audience by giving real case scenarios, corresponding patterns illustrated by UML class diagrams. To summarize, you should analyze the relationship between the object-orientated paradigm and design patterns. The presentation should be about approximately 20-30 minutes and it should be summarized of the team report. Learning Outcomes and Assessment Criteria Pass Merit Distinction LO1 Examine the key components related to the object-orientated programming paradigm, analysing design pattern types P1 Examine the characteristics of the object-orientated paradigm as well as the various class relationships. M1 Determine a design pattern from each of the creational, structural and behavioural pattern types. D1 Analyse the relationship between the object- orientated paradigm and design patterns. LO2 Design a series of UML class diagrams P2 Design and build class diagrams using a UML tool. M2 Define class diagrams for specific design patterns using a UML tool. D2 Define/refine class diagrams derived from a given code scenario using a UML tool.
Chapter 1: Examine the key components related to the object-orientated programming paradigm, analyzing design pattern types
1. OOP general concepts Programming languages that use objects are known as "object-oriented programming," or OOPs. The objective of object-oriented programming is to incorporate real-world ideas like inheritance, hiding, polymorphism, etc. into computer code. The main objective of OOP is to connect the functions that use the data and the data itself, ensuring that only that function and no other part of the code can access the data (sambhav228, 2020) OOPs Concepts: Class Objects Data Abstraction Encapsulation Inheritance Polymorphism Dynamic Binding Message Passing (sambhav228, 2020) 2. Class An individual data type is a class. When a class instance is created, its data members and member functions can be accessed and used. It stands for the collection of traits or operations that all objects of a particular type share. A class is comparable to an object's blueprint (sambhav228, 2020) Figure 1 Class example Code example: New objects are initialized in class constructors. Methods are used to implement the action of the class and its objects, whereas fields are variables that supply the state of the class and its objects (Mangal, 2022)
Figure 3 Object example Example : A class is said to be instantiated when its object is produced. Every instance shares the traits and behaviors of the class. The states of such properties, or their values, are unique to each object. There is no limit to how many instances there can be of a single class (Mangal, 2022) Code :
// C# program to illustrate the // Initialization of an object using System; // Class Declaration public class Dog { // Instance Variables String name; String breed; int age; String color; // Constructor Declaration of Class public Dog(String name, String breed, int age, String color) { this.name = name; this.breed = breed; this.age = age; this.color = color; } // Property 1 public String GetName() { return name; } // Property 2 public String GetBreed() { return breed; } // Property 3 public int GetAge() { return age; } // Property 4 public String GetColor() {
Figure 5 Data Abstraction example // C# program to calculate the area // of a square using the concept of // data abstraction using System; namespace Demoabstraction { // abstract class abstract class Shape { // abstract method public abstract int area(); } // square class inheriting // the Shape class class Square : Shape { // private data member private int side; // method of square class public Square(int x = 0) {
side = x; } // overriding of the abstract method of Shape // class using the override keyword public override int area() { Console.Write("Area of Square: "); return (side * side); } } // Driver Class class GFG { // Main Method static void Main(string[] args) { // creating reference of Shape class // which refer to Square class instance Shape sh = new Square(4); // calling the method double result = sh.area(); Console.Write("{0}", result); } } } Output: Figure 6 Output of Data Abstraction (saini, 2021) 5. Encapsulation Data wrapped up into a single unit is referred to as encapsulation. It serves as the link between the code and the data that it works with. With encapsulation, a class's variables or data are kept private from other classes and are only accessible through member functions of the class in which they were declared. Data-
get { return studentAge; } set { studentAge = value; } } } // Driver Class class GFG { // Main Method static public void Main() { // creating object DemoEncap obj = new DemoEncap(); // calls set accessor of the property Name, // and pass "Ankita" as value of the // standard field 'value' obj.Name = "Ankita"; // calls set accessor of the property Age, // and pass "21" as value of the // standard field 'value' obj.Age = 21; // Displaying values of the variables Console.WriteLine("Name: " + obj.Name); Console.WriteLine("Age: " + obj.Age); } } Output: Figure 8 Ouptput of Encapsulation
(Saini, 2019) 6. Inheritance A crucial OOP tenet is inheritance (Object-Oriented Programming). Inheritance refers to a class's capacity to inherit traits and properties from another class. The properties of other classes are inherited when we create a class. Therefore, since properties and functions can be inherited from another class that already has them, we do not need to write them all by hand when we build a class. The user can reuse code and lessen its redundancy by using inheritance whenever possible (sambhav228, 2020) Figure 9 Inheritance example Example: The base class in the inheritance example below is called GFG, the derived class is called GeeksforGeeks, and the driver class is called Sudo (Mangal, 2019) Code: // C# program to illustrate the // concept of inheritance using System; namespace ConsoleApplication1 { // Base class class GFG { // data members public string name; public string subject; // public method of base class public void readers(string name, string subject) {
7. Polymorphism Polymorphism refers to the existence of various forms. Polymorphism can be simply defined as a message's capacity to be presented in multiple forms. One person may, for instance, exhibit several different traits at once. A father, a husband, and an employee are all dual roles that a man plays. Therefore, the same person exhibits diverse behavior depending on the circumstance. Polymorphism is the term for this (sambhav228, 2020) Example: Take the Animal base class, for example, which has a function called animalSound (). Animals that are descended from pigs, cats, dogs, and birds each have their own unique animal sound (the pig oinks, while the cat meows). Figure 11 Polymorphism example class Animal // Base class (parent) { public void animalSound() { Console.WriteLine("The animal makes a sound"); } } class Pig : Animal // Derived class (child) { public void animalSound() { Console.WriteLine("The pig says: wee wee"); }
class Dog : Animal // Derived class (child) { public void animalSound() { Console.WriteLine("The dog says: bow wow"); } } class Program { static void Main(string[] args) { Animal myAnimal = new Animal(); // Create a Animal object Animal myPig = new Pig(); // Create a Pig object Animal myDog = new Dog(); // Create a Dog object myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } } Output: Figure 12 Output of polymorphism (w3schools, 2022)
8. Method Overloading Polymorphism is typically implemented by method overloading. It is the capacity to reinterpret a function in several ways. By specifying two or more functions in a class with the same name, a user can implement function overloading. The varied method signatures in C# allow for method differentiation. In other words, methods inside the same class can have the same name but distinct parameter lists (i.e., the number of parameters, their order, and their data types) (Akanksha_Rai, 2021) Based on the quantity and kind of parameters that are supplied to the methods as arguments, overloaded methods are distinguished. More than one method definition cannot share the same name, order, or argument type. A compiler error would result.