Assignment 1 Unit 20 Advanced Programming, Essays (university) of Advanced Data Analysis

P1: The characteristics of the object-orientated paradigm

Typology: Essays (university)

2020/2021

Uploaded on 10/06/2021

unknown user
unknown user šŸ‡»šŸ‡³

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification TEC 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 BHAF
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 D2
~ 1 ~
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Assignment 1 Unit 20 Advanced Programming and more Essays (university) Advanced Data Analysis in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification TEC 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 BHAF 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

ā’ Summative Feedback: ā’ Resubmission Feedback:

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

I. Introduction

ā€˜Object-Oriented Programming’’ and ā€˜ā€˜Data Abstraction’’ have become very common terms. Unfortunately, few people agree on what they mean. In this assignment I will explain the characteristics of object-oriented programming such as encapsulation, inheritance, polymorphism, ... as well as different class relationships. After that, I will design a class diagram based on a given code scenario. This report consists of two sections:

  1. The characteristic of the object-oriented paradigm as well as the various class relationships.
  2. Design a UML class diagrams.

II. The characteristics of the object-

orientated paradigm

OOP stands for Object-Oriented Programming. Object-oriented programming is a methodology or paradigm to design a program using classes and objects. OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. An OO program: ā€œa bunch of objects telling each other what to do by send messagesā€. Some benefits of OOP: ļ‚· Better abstractions (modeling information and behavior together). ļ‚· Better maintainability (more comprehensible, les fragile). ļ‚· Better reusability (classes as encapsulated components). OOP has many features that make it useable including the followings: ļ‚· Object ļ‚· Class ļ‚· Inheritance ļ‚· Polymorphism ļ‚· Abstraction ļ‚· Encapsulation. Let’s discuss above each OOPs concepts with real-world example.

1. Object

The two most important concepts in object-oriented programming are the class and the object. The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables like the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword in Java Programming language. A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. I can find various Object definitions as:

  1. An object is a real-world entity.
  2. An object is a runtime entity.
  3. An object is a thing, both tangible and intangible, that we can imagine.
  4. The object is an instance of class. Real-world examples ļ‚· A dog is an object because it has state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Chair, Bike, Marker, Pen, Table, Car, Book, Apple, Bag etc. It can be physical or logical (tangible and intangible). ļ‚· Bicycle is an object. Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).

From the above program, the Student object are: Each of these statements has three parts (discussed in detail below): Declaration: The code Student student ; declarations that associate a variable name with an object type. Instantiation : The new keyword is a Java operator that creates the object. Initialization : The new operator is followed by a call to a constructor, which initializes the new object. 1) Declaring a Variable to Refer to an Object General syntax; type name; This notifies the compiler that you will use a name to refer to data whose type is a type. With a primitive variable, this declaration also reserves the proper amount of memory for the variable. From the above program, we can declare variables to refer to an object as:

2) Instantiating a Class The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the object constructor. For example: Note that we have used a new keyword to create Student objects. 3) Initializing an Object The new keyword is followed by a call to a constructor, which initializes the new object. For example: From above code will call below constructor in Student class.

2. Class

A class is a group of objects which have common properties. A class is a kind of mold or template that dictates what objects can and cannot do. An object is called an instance of a class. An object is an instance of exactly one class. An instance of a class belongs to the class. In short, a class is the specification or template of an object. Once a class is defined, we can create as many instances of the class as a program requires. Figure below shows a diagram that we will use throughout the book to represent a class.

Output:

3. Abstraction

Abstraction means hiding the lower-level details and exposing only the necessary and relevant details to the user. Real-world example

  1. As a first example, let's consider a Car , which abstracts the internal details and exposes to the drive only those details that relevant to the interaction of drive with the Car.
  1. The second example, consider an ATM Machine; All are performing operations on the ATM machine like cash withdrawal, money transfer, retrieve mini statement…etc. but we cannot know internal details about ATM. Implement with example. For example : Employee, Contractor, and Fulltime Employee Example In this example, we create an abstract Employee class and this class contains the abstract mathSalary () method. Let the subclasses extend the Employee class and implement the CalculSalary () method. Let's create Contractor and FullTimeEmployee classes as we know that the salary structure for a contractor and full-time employees are different so let these classes to override and implement a calculateSalary () method.

Step 2 : The Contractor class inherits all properties from its parent abstract Employee class but have to provide its own implementation to calculateSalary () method. In this case, we multiply the value of payment per hour with given working hours. Step 3 : The FullTimeEmployee also has its own implementation of calculateSalary () method. In this case, we just multiply by a constant value of 8 hours. Step 4 : Let's create a AbstractionDemo class to test implementation of Abstraction with below code:

4. Encapsulation

Encapsulation is a process of wrapping of data and methods in a single unit is called encapsulation. In OOP, data and methods operating on that data are combined together to form a single unit, which is referred to as a Class. Real-world example

  1. Capsule , it is wrapped with different medicines. In a capsule, all medicine is encapsulated inside a capsule.
  2. To better put it in a simple way, Let’s say I have 2 Cars - A Ford GT & A Chevrolet Camaro. Let’s say my Ford GT & Camaro are having Petrol Engines. I can change my cars color, lights, Visual Appearances etc.… but cannot switch it to Diesel and It would not work if I were to use diesel for these cars. Implement with example Consider below Person class diagram, the id and nam e parameters should not be accessed directly outside Person class - achieved by private declaration.

Output:

5. Inheritance

The Inheritance is a process of obtaining the data members and methods from one class to another class, plus can have its own is known as inheritance. It is one of the fundamental features of object-oriented programming. Inheritance - relationship between a superclass and its subclasses. ļ‚· Sub class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. ļ‚· Super class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class. This can be visualized as follows.

In class diagrams such as this, subclasses point up to their superclass. The attributes and behaviors implemented in the superclass are ā€œinheritedā€ by all the subclasses. The attributes and behaviors implemented in one of the subclasses are unique that subclass. In a sense, the features shared by subclass1 and subclass 2, that might otherwise have been implemented separately in each of the subclasses, can be collected and ā€œraised upā€ into the single shared superclass. Real-world example

  1. Real-life examples of inheritance are children and parents, all of a father's property is inherited by his son.
  2. In the Java library, you can see extensive use of inheritance. The following figure shows a partial inheritance hierarchy from the java.lang library. The Number class abstracts different numeric (reference) types such as Byte , Integer , Float, Double, Short , and BigDecimal.

Notice that the modifier for the instance variables is protected, making them visible and accessible from the instance methods of the class and the descendant classes. If I declare a data member of a class private, then this data member is accessible from the methods of the

class only. If I declare a data member public, this data member is accessible from everywhere. We declare them protected so they are accessible from both the methods of the class and the descendant classes. I will define the classes UndergraduateStudent and GraduateStudent as subclasses of the Student class. In Java, we say a subclass extends its superclass. The difference between the classes GraduateStudent and UndergraduateStudent lies in the way their final course grades are computed. The two subclasses are defined as follows: Figure below shows the class diagram relating the three classes. By seeing an inheritance arrow connecting a subclass to its superclass, we know that data members and methods indicated on the superclass are applicable to the subclasses also.