Docsity

Object-Oriented Programming Concepts and Class Relationships, Study Guides, Projects, Research of Cyberlaw and Internet Law

Toggle sidebar
bg1
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
Ho Hoang Quoc Viet
Student ID
GCD210004
Class
GCD1101
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
VIET
Grading grid
P1
P2
M1
M2
D1
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Object-Oriented Programming Concepts and Class Relationships and more Study Guides, Projects, Research Cyberlaw and Internet Law 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 Ho Hoang Quoc Viet Student ID GCD

Class GCD 1101 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 VIET

Grading grid

P1 P2 M1 M2 D1 D

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

I. Examine the characteristics of the object-orientated paradigm as well as the

various class relationships. (P1)

1. Object-oriented programming:

  • Object-Oriented Programming (OOP) is a programming paradigm in computer science that relies on the concept

of classes and objects. It is used to structure a software program into simple, reusable pieces of code blueprints

(usually called classes), which are used to create individual instances of objects. There are many object-oriented

programming languages, including JavaScript, C++, Java, and Python.

  • OOP languages are not necessarily restricted to the object-oriented programming paradigm. Some languages,

such as JavaScript, Python, and PHP, all allow for both procedural and object-oriented programming styles.

  • A class is an abstract blueprint that creates more specific, concrete objects. Classes often represent broad

categories, like Car or Dog that share attributes. These classes define what attributes an instance of this type will

have, like color, but not the value of those attributes for a specific object.

  • Classes can also contain functions called methods that are available only to objects of that type. These functions

are defined within the class and perform some action helpful to that specific object type.

For example , say we created a class, Car, to contain all the properties a car must have, color, brand, and model.

We then create an instance of a Car type object, myCar to represent my specific car. We could then set the value

of the properties defined in the class to describe my car without affecting other objects or the class template. We

can then reuse this class to represent any number of cars.

In this example, the Car class represents a blueprint for creating car objects. It has properties ( Make and

Model ) that define the car's attributes. It also has methods ( StartEngine and Accelerate ) that define the car's

behavior.

2.2. Objects

object is an instance of a class. It represents a specific realization of the class blueprint. In the case of a car, an object could be created to represent a specific car with its own unique characteristics.

In this example, an object of the Car class is created using the new keyword. The object is assigned to the myCar variable. Properties ( Make and Model ) of the object are set to specific values. The StartEngine method is called on the myCar object.

2.3. Encapsulation

Encapsulation is one of the core principles of object-oriented programming (OOP) that promotes the idea of bundling data and methods together within a class and controlling access to them. It allows for the organization and management of the internal state and behavior of an object. In encapsulation, the internal data of an object is kept private or protected from direct external access. Instead, access to the object's data is provided through methods, known as getters and setters, which are defined within the class. This helps ensure data integrity and provides a level of abstraction. Benefits of encapsulation include:

  • Data hiding: Encapsulation allows for the hiding of internal implementation details of an object. The private or protected data members cannot be accessed directly from outside the class, preventing unauthorized modification or access.
  • Modularity and code maintainability: Encapsulation helps in dividing a complex system into smaller, more manageable modules (classes). Each class can have its own internal implementation, providing encapsulation within that class. This promotes code maintainability by allowing changes to be made to a class without affecting other parts of the program.
  • Data integrity: By controlling access to data through methods, encapsulation allows for data validation and safeguards against invalid data being stored in the object's properties. This helps maintain data integrity and ensures that the object's state remains consistent. Here's an example that demonstrates encapsulation in C# using a car class:

2.4. Inheritance

Inheritance is a fundamental concept in object-oriented programming (OOP) that allows one class to inherit the properties and methods of another class. It enables code reuse and promotes the creation of hierarchical relationships between classes. Inheritance involves two key concepts:

  • Base Class (Parent Class / Superclass): A base class is the class that is being inherited from. It defines the common properties and behaviors that can be shared by multiple derived classes.
  • Derived Class (Child Class / Subclass): A derived class is the class that inherits from the base class. It inherits all the members (properties, methods, etc.) of the base class and can add its own specific members or modify the inherited members. Benefits of inheritance include:
  • Code reuse: Inheritance allows you to reuse the code from the base class in the derived class. The derived class automatically has access to all the public and protected members of the base class, saving you from writing the same code again.
  • Modularity: Inheritance promotes modularity by organizing related classes into a hierarchical structure. You can define a base class with common attributes and behaviors, and then create specialized derived classes that inherit and extend the functionality of the base class.
  • Polymorphism: Inheritance is closely related to the concept of polymorphism. Polymorphism allows objects of different derived classes to be treated as objects of the base class. This enables writing code that can work with objects of different types but still exhibit the same behavior defined in the base class. Here's an example that demonstrates inheritance in C# using a base class called Vehicle and a derived class called Car:

In the example above, the Vehicle class serves as the base class, and the Car class is derived from it using the : symbol. The Car class inherits the Make , Model , and Year properties as well as the StartEngine() method from the base class. The Car class also adds its own Accelerate() method and overrides the Drive() method from the base class to provide its own implementation. Through inheritance, the Car class inherits the common attributes and behaviors of the Vehicle class, while also having the ability to extend and customize its own specific functionality.

2.5. Polymorphism

Polymorphism means the ability of objects to take on multiple forms. It allows different objects to respond

differently to the same method call. Polymorphism can be achieved through method overriding (inheriting and

Abstraction focuses on simplifying complex systems by providing a simplified and generalized representation. In OOP, abstraction is achieved through abstract classes and interfaces. Abstract classes define a common structure and behavior for a group of related classes, while interfaces define a contract that classes must implement. Abstraction also serves an important security role. By only displaying selected pieces of data and only allowing data to be accessed through classes and modified through methods, we protect the data from exposure. To continue with the car example, you wouldn’t want an open gas tank while driving a car.

3. Various class relationship

3.1. Inheritance

Inheritance allows a class (subclass or derived class) to inherit the properties and methods of another class (superclass or base class). The subclass can extend or specialize the behavior of the superclass while inheriting its common characteristics. Inheritance represents an "IS-A" relationship, where a subclass is a specific type of the superclass. For example, the bank account can be of two types; Savings Account and Credit Card Account. Both the savings and the credit card account inherits the generalized properties from the Bank Account, which is Account Number, Account Balance, etc.

3.2. Composition

Composition represents a "HAS-A" relationship, where a class contains another class as a part of its state. The containing class is responsible for creating and managing the contained class.

3.4. Association

Association represents a relationship between two or more classes, indicating that objects of one class are connected or interact with objects of another class. It can be a one-to-one, one-to-many, or many-to-many relationship.

  • Reflexive Association : The reflexive association is a subtype of association relationship in UML. In a reflexive association, the instances of the same class can be related to each other. An instance of a class is also said to be an object. For example, Let us consider an example of a class fruit. The fruit class has two instances, such as mango and apple. Reflexive association states that a link between mango and apple can be present as they are instances of the same class, such as fruit.
  • Directed Association: As the name suggests, the directed association is related to the direction of flow within association classes. In a directed association, the flow is directed. The association from one class to another class flows in a single direction only. It is denoted using a solid line with an arrowhead.

For example, You can say that there is a directed association relationship between a server and a client. A server can process the requests of a client. This flow is unidirectional, that flows from server to client only. Hence a directed association relationship can be present within servers and clients of a system.

3.5. Dependency

Dependency occurs when a class uses another class temporarily or indirectly. It represents a "uses" relationship between classes. In dependency, one class depends on the functionality provided by another class, but there is no ownership or permanent association between them For example , the Car class has a dependency on the CarFactory class. In this case, the dependency is an instantiate dependency, where the Car class is an instance of the CarFactory class.

II. Design a series of UML class diagrams