0% found this document useful (0 votes)
134 views36 pages

Unit 20 - Assignment 1 Frontsheet

The document is an assignment front sheet for a BTEC Level 5 HND Diploma in Computing unit on Advanced Programming. It includes information such as the qualification, unit number and title, submission date, student details, and grading criteria. The student declares that the assignment is their own work and understands the consequences of plagiarism. Spaces are provided for summative and resubmission feedback as well as the grade, assessor signature, and lecturer signature.

Uploaded by

Võ Ngọc Hùng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views36 pages

Unit 20 - Assignment 1 Frontsheet

The document is an assignment front sheet for a BTEC Level 5 HND Diploma in Computing unit on Advanced Programming. It includes information such as the qualification, unit number and title, submission date, student details, and grading criteria. The student declares that the assignment is their own work and understands the consequences of plagiarism. Spaces are provided for summative and resubmission feedback as well as the grade, assessor signature, and lecturer signature.

Uploaded by

Võ Ngọc Hùng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

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 Student ID

Class GCH0705 Assessor name Doan Trung Tung

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
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Table of Contents
I.OOP..................................................................................................................................................................................................................3
1.Object...........................................................................................................................................................................................................3
2.Class..............................................................................................................................................................................................................4
3. Example.......................................................................................................................................................................................................4
III. Encapsulation..............................................................................................................................................................................................8
1.Definition Encapsulation..............................................................................................................................................................................9
2. Access Modifiers..........................................................................................................................................................................................9
3. Property.....................................................................................................................................................................................................10
4. For example...............................................................................................................................................................................................10
IV.Inheritance..................................................................................................................................................................................................13
1. Definition Inheritance...............................................................................................................................................................................13
2. For example...............................................................................................................................................................................................13
V. Polymorphism.............................................................................................................................................................................................19
1.Method Overloading..................................................................................................................................................................................19
2.Method Overriding:...................................................................................................................................................................................21
VI.Abstraction.................................................................................................................................................................................................26
1. Definition :.............................................................................................................................................................................................26
2. Abstract Class........................................................................................................................................................................................27
3. Interface.................................................................................................................................................................................................31
4 Interface vs Abstract Class.........................................................................................................................................................................34
References.........................................................................................................................................................................................................35
ASM Advanced Programming

P1&P2 Examine the characteristics of the object-orientated paradigm as well as the various class relationships.

I.OOP
OOP (brief for Object Oriented Programming) – item-orientated programming is a programming approach primarily based
totally at the idea of instructions and items. OOP makes a speciality of manipulating items instead of the common sense for
manipulating them.

The purpose of OOP is to optimize supply code management, growth reusability, and maximum importantly, assist
encapsulate approaches with acknowledged residences via the usage of items.

1.Object
Objects in OOP include 2 principal components:

Attributes: are the records and traits of the item

Methods: are the behaviors that the item can perform

To make it less complicated to imagine, we've got a real-lifestyles instance of an item that could be a phone. This item will
have:
Attributes: color, memory, working system…

Methods: calling, taking photos, texting, recording...

2.Class
Class is an abstraction of the item. Objects with comparable residences are grouped right into a magnificence. The
magnificence may even consist of portions of records: residences and methods.

An item could be dealt with for instance of the magnificence.

Continuing the instance withinside the item segment above, we've got a phone magnificence including 2 components:

Attributes: color, memory, working system…

Methods: calling, taking photos, texting, recording...

Objects of this magnificence can be: iPhone, Samsung, Oppo, Huawei...

3. Example
 Create a Class:

o Create a new class named "Animal"


 Class Members

- Class contributors consist of fields and homes and keyword ”public” is an get entry to modifier.

- The fields which are taken into consideration traits of gadgets inclusive of name, age, height, weight ... You
also can set the preliminary rate for the sector proper after initialization

- Properties are the actions of that object such as eating, running, emitting a cry...

 Constructors
o A constructor is a special method that is used to initialize objects. The advantage of a constructor
is that it is called when an object of a class is created. It can be used to set initial values for fields
o The constructor ought to suit the elegance call and it can not have a go back type (void, int so
on ...).
o The constructor is referred to as whilst the item is created.
o The constructor assist shop time.
 Diagram

o "+" corresponds to the sphere or technique this is of kind public


o The row "peak: double" right here method that we claim a variable peak of facts kind double and the
identical is going for all different variables.
o row "Animal ()" is a illustration of a constructor of sophistication Animal and it has no go back kind.
o The "Run (): void" row represents it as a feature withinside the magnificence and has the go back kind
void.
 Create a Object

To create a "Animal", specify the call after the challenge and use the new "new":
o You can create multiple objects of one class:

Calling methods in main:


Run Code:
III. Encapsulation

1.Definition Encapsulation
Encapsulation permits hiding records and the inner processing homes of the item. Other items can't immediately have an
effect on the facts internal and extrade the kingdom of the item, however should undergo public strategies supplied via way
of means of that item.

2. Access Modifiers
 Definition : All sorts and kind contributors have an accessibility degree. The accessibility degree controls whether or
not they may be used from different code on your meeting or different assemblies. Use the subsequent get right of
entry to modifiers to specify the accessibility of a kind or member whilst you claim it:

public: The kind or member may be accessed with the aid of using every other code withinside the identical meeting or
some other meeting that references it.
non-public: The kind or member may be accessed best with the aid of using code withinside the identical magnificence or
struct.

included: The kind or member may be accessed best with the aid of using code withinside the identical magnificence, or in a
category this is derived from that magnificence.

internal: The kind or member may be accessed with the aid of using any code withinside the identical meeting, however
now no longer from some other meeting.

included internal: The kind or member may be accessed with the aid of using any code withinside the meeting wherein it is
declared, or from inside a derived magnificence in some other meeting.

non-public included: The kind or member may be accessed best inside its asserting meeting, with the aid of using code
withinside the identical magnificence or in a kind this is derived from that magnificence.

Property is contributors named the layers, structure, and Interface. The versions of contributors or protocol in a study room
or systems are known as the Field. Properties are an inheritance of the Field and are accessed through the use of the equal
tool. They use accessor via Private Field values may be read, written and manipulated.

3. Property
 Definition : Property Property does now no longer call the archives. Instead, they have got accessors to read, write or
calculate their values.

This assets enables to boom the safety of the item and keep away from accidental facts corruption.

4. For example
 Height and width here are the properties (properties) of the class object hinhchunhat
 Tinhdientich() is a method that is public for the purpose of interacting with other objects. Create a class Program
with a static method to run, see how to interact and change the properties of the object through public methods:
Run Code :

So whilst we need to alternate the properties (properties), we can not have interaction without delay with the properties,
however must undergo public strategies described in the class,
We can not understand the inner common sense of the object.

Diagram:
IV.Inheritance
1. Definition Inheritance
This is a feature that is used quite a lot. Inheritance allows building a new class (Child class), inheriting and reusing
properties and methods based on the old class (Parent class) that existed before.

Child classes inherit all the members of the Parent class and do not need to be redefined. Subclasses can extend inherited
components or add new ones.

2. For example
Single level Inheritance : With a parent class and a child class.

o We have class Animal (father) with fields: height, weight, name, age.

Methods are: Eat() and Drink().


o Then create one more class Dog (Child) that inherits from class Animal (parent). By line of code Class Dog : Animal

The Dog class also has a color field and a Bark() method
Since here dog has inherited Animal, there are methods and fields of animal we can call them in main function.

Run Code :
o So we only create an object of the Dog class, but that object can still use the fields and methods of the Animal class
because the Dog class inherits the Animal class.

o Class Diagram of Single level Inheritance:


Multiple level Inheritance: Multiple levels of inheritance

O The identical applies with the instance above. We create some other Puppy magnificence that inherited the Dog
magnificence with 1 field: Legs and a method: Cry()

- In the Class Program, we create a puppy object of the puppy class. We then give that object access to the fields and
methods of the Puppy class, Dog class and the Animal class as shown below
Run Code:
- In the Puppy magnificence most effective the Legs area and the Cry () technique are available, however right here we
will nevertheless get entry to the Color area of the Dog magnificence and the Eat () technique of the Animal
magnificence. Because it inherits the Dog magnificence and the Dog magnificence inherits from the Animal
magnificence, it may use the fields of the 2 instructions above. This is known as multi-stage inheritance

- Class Diagram of Multiple stage Inheritance:


V. Polymorphism
Polymorphism in OOP programming permits one-of-a-kind gadgets to carry out the identical feature in one-of-a-kind ways.

1.Method Overloading
Is a manner to overload strategies with the identical call however special parameters

For Example :

Create class MathOperation

We want to add 3 add methods with the same name but different parameters as the code below.

The first method Add has 2 parameters int a, int b.

The second method Add has 3 parameters double a, double b, double c,

The 3rd method Add has 3 parameters decimal a, decimal b, decimal c,


And call the main function with the corresponding values.

Diagram:
Run code :

When we run it we get 3 different results. We have loaded 3 different corresponding values and called them to main
function.

2.Method Overriding:
This is a technique that overwrites the digital strategies of a sure superclass (declared with the digital keyword).

To specific this approach want to apply 2 keywords:


virtual : key-word used to claim a digital approach (overridable).

override: key-word used to mark the approach to override the approach of the discern class.

For Example:

Create a superclass Animal with fields and methods But with method declaration with virtual keyword. And 2 subclasses,
Dog and Cat, inherit Animal

When using virtual and overestimate the outcome of the performance, this time from the lock has been priority and
overwrite the method from the father's class, When the subjects call the same method "Speak" it will be pointed to the
corresponding method of each object created.
Override has taken precedence and overrides the virtual method from the superclass, when objects call the EXplainSelf()
method it will point to the corresponding method of each instantiated object.
Diagram:
VI.Abstraction
1. Definition :
Abstraction removes the pointless complexity of the item and focuses best on what's critical and important.
2. Abstract Class

In summary elegance there are 2 sorts of methods:

summary technique (an empty technique that does nothing)

everyday technique (remains has common sense to go back records or carry out a few action, it's miles used for widespread
purposes)

It's kind of like Interface, but he can do more work.

There are two types of methods as abstract method and method:

The abstract method is empty method.

The method is usually an execution method.

The class can only inherit a Abstract class.

Heading to your calculations and your executable features are used as general functions for the class extend.

For Example:

Abstract class animal has 2 method is abstract method and method(Eat class Dog class Dog class and Cat inherited the
abstract method.
Create the abstract class animal contains 2 method, a abstract method and a method that is usually implemented. As you can
see, the class Dog, Cat can only extend a abstract class, and only implement the method of the ractical abstract method and
implement method can still use, which can also write a Eat method, with virtual lock in the Cat may not practice method.

Run code:
Diagram:

3. Interface
Quite just like summary magnificence however interface isn't always magnificence, in interface handiest announces
empty methods/homes with out a implementation, implementation might be proven in inherited classes, interface is
sort of a template framework to implementation and comply with classes.
It's not class.
Only containing method/empty properties are no execution.
It's like a pattern, a frame for implement and follow.
The classes can implements a lot of interface.
As a contract, the implement class must deploy method as interface.
For Example:
• Interface may be described the usage of the interface keyword. An interface can include declarations of techniques,
properties, indexers, and events (with empty bodies). However, it can't include fields, auto-carried out properties.
• An interface is a completely "summary class", which could simplest include summary techniques and properties
(with empty bodies):
• Example of interface:
o Create interface IAnimal:

Typically the interface call begins offevolved with the letter "I" so that you can without problems distinguish that it's
miles an interface instead of a class.
o In order to get entry to interface methods, the interface wishes to be implemented (inherited) through some other
class. The following instance will make this clear:
Run code :

Diagram:
4 Interface vs Abstract Class
Priority:

Interface

Could inherit many interface.

Building a model that the layers must follow.

Helping a good manager, getting the functions has to be given to someone.

Abstract class

Could have flexed the method. Like a regular class.

The class can't override or override the usual method.

Disarm point:

Interface:

Every time I define the calculations, the class impeccable they have to add that feature, there's a possibility of nothing to do with it.

Abstract class

Can't extend much abstract class.


References
https://viblo.asia/p/4-dac-tinh-cua-lap-trinh-huong-doi-tuong-object-oriented-program-XL6lAA7Nlek. (n.d.).

https://viblo.asia/p/khac-nhau-giua-abstract-class-va-interface-khi-nao-dung-chung-ORNZq9YrZ0n. (n.d.).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy