Asm 1
Asm 1
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.
Grading grid
P1 P2 M1 M2 D1 D2
Summative Feedback: Resubmission Feedback:
Figure 1 ............................................................................................................................................................................................ 7
Figure 2 ............................................................................................................................................................................................ 8
Figure 3 ............................................................................................................................................................................................ 9
Figure 4 .......................................................................................................................................................................................... 10
Figure 5 .......................................................................................................................................................................................... 11
Figure 6 .......................................................................................................................................................................................... 11
Figure 7 .......................................................................................................................................................................................... 12
Figure 8 .......................................................................................................................................................................................... 12
Figure 9 .......................................................................................................................................................................................... 13
Figure 10 ........................................................................................................................................................................................ 13
Figure 11 ........................................................................................................................................................................................ 13
Figure 12 ........................................................................................................................................................................................ 14
Figure 13 ........................................................................................................................................................................................ 14
Figure 14 ........................................................................................................................................................................................ 15
Figure 15 ........................................................................................................................................................................................ 16
Figure 16 ........................................................................................................................................................................................ 16
Figure 17 ........................................................................................................................................................................................ 17
Figure 18 ........................................................................................................................................................................................ 17
Figure 19 ........................................................................................................................................................................................ 18
Figure 20 ........................................................................................................................................................................................ 18
Figure 21 ........................................................................................................................................................................................ 19
Figure 22 ........................................................................................................................................................................................ 19
Figure 23 ........................................................................................................................................................................................ 21
Figure 24 ........................................................................................................................................................................................ 21
Figure 25 ........................................................................................................................................................................................ 21
Figure 26 ........................................................................................................................................................................................ 22
Figure 27 ........................................................................................................................................................................................ 23
Figure 28 ........................................................................................................................................................................................ 23
Figure 29 ........................................................................................................................................................................................ 24
Figure 30 ........................................................................................................................................................................................ 24
Figure 31 ........................................................................................................................................................................................ 24
Figure 32 ........................................................................................................................................................................................ 25
Figure 33 ........................................................................................................................................................................................ 25
Figure 34 ........................................................................................................................................................................................ 26
Figure 35 ........................................................................................................................................................................................ 26
Figure 36 ........................................................................................................................................................................................ 27
Figure 37 ........................................................................................................................................................................................ 27
Figure 38 ........................................................................................................................................................................................ 27
Figure 39 ........................................................................................................................................................................................ 28
Figure 40 ........................................................................................................................................................................................ 28
Figure 41 ........................................................................................................................................................................................ 28
Figure 42 ........................................................................................................................................................................................ 29
Figure 43 ........................................................................................................................................................................................ 29
Figure 44 ........................................................................................................................................................................................ 29
Figure 45 ........................................................................................................................................................................................ 30
ASSIGNMENT
CHAPTER 1: GENERAL CONCEPTS AND CHARACTERISTICS OF OBJECT-
ORIENTED PROGRAMMING (OOP).
I. OOP general concepts.
1. Introduce OOP.
Object-oriented programming (OOP) is a programming paradigm based on the concept of
"objects", which may contain data, in the form of fields, often known as attributes; and
code, in the form of procedures, often known as methods. For example, a person is an
object which has certain properties such as height, gender, age, etc. It also has certain
methods such as move, talk, and so on.
2. Object.
An object consists of two pieces of information: properties and methods.
• Properties are the information and characteristics of the object. For example,
humans have characteristics such as eyes, nose, hands, feet, etc.
• Methods are operations and actions that an object can perform. For example, a
person would be able to do the act of speaking, walking, eating, drinking, . . .
Figure 1
3. Class.
A class is a data type consisting of predefined properties and methods. This is the
abstraction of the object. Unlike a normal data type, a class is a (abstract) unit consisting
of a combination of methods and properties. More roughly, objects with similar
properties are grouped into a class of objects.
Figure 2
Figure 3
Figure 6
❖ Explanations:
o The class Company is encapsulated in the above program since the variables
are declared as private.
o The Name and Address and Years Begin accessors, which contain the get and
set methods for retrieving and setting the values of private fields, are used to
access these private
o variables.
o Accessors are declared as public so that they can access in other classes.
2. Inheritance.
• Inheritance allows us to define a class in terms of another class, which makes it
easier to create and maintain an application. This also provides an opportunity for
code reuse and faster execution times.
• Inheritance in C# is used with ampersands:
• When creating a class, instead of writing all new data members and member
functions, the programmer might be better off inheriting the members of an
existing class. This existing class is called the Base Class - the base class, and the
new class is referred to as the Derived Class - the derived class.
❖ For example: Descriptions of OOP scenario: You need to design the program so that
the employee's name, age, position, office location, and job can be displayed on the
screen.
❖ Include Class Diagram
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
❖ Explanation
o I created the class MyMemployee.
o The class MyGeneralM is an extension of the parent class MyMemployee. It
inherits all its fields and methods, plus defines two additional fields that only
belong to MyGeneralM.
o To test the MyGeneralM class I instantiate a new MyGeneralM object and
printed out all the information
3. Abstraction.
• Abstraction is a process of hiding the implementation details and exposing the
feature only to the user. Abstraction allows you to eliminate the complexity of an
object by exposing only the properties and methods that are needed by the object
in programming.
• Abstraction and encapsulation are two related characteristics in object-oriented
programming. Abstraction allows making related information visible, and
encapsulation gives the programmer the ability to implement inherited
abstraction.
❖ Example: Descriptions of OOP scenario: You need to design the program so that it
shows the salary of the manager, and the manager is holding the employee's salary.
❖ Include Class Diagram.
o Override
Figure 12
o Overloading
Figure 13
Figure 16
❖ Explanation.
o I create the OverrideEmployee class with the iWork() method.
o The LManager class extends the OverrideEmployee class. Both have an iWork ()
method. By default, LManager inherits its parent’s iWork () method. However,
since it also defines its own iWork() method.
o The OverloadManager class has three work () methods. The first parameter
does not have any parameters, the second has one parameter (salary) and the
third has two parameters (name and salary).
4. Polymorphism.
• The word polymorphism means having many forms. In object-oriented
programming, polymorphism is often expressed as "one interface, many
functions". In c#, polymorphism is divided into two types: static polymorphism and
dynamic polymorphism (2 keywords overloading and overriding).
• Static polymorphism: The technique of binding a function to an object at compile
time is called Early Binding. It is also called Static Binding. C# provides two
techniques for implementing static polymorphism. They are:
o Function overloading
o Operator overloading
❖ Dynamic polymorphism: Dynamic polymorphism in C# is implemented by abstract
classes and virtual functions.
❖ Example: Descriptions of OOP scenario: You need to design the program so that
it shows the salary of the manager, and the manager is holding the employee's
salary.
❖ Include Class Diagram.
o Override.
Figure 17
o Overloading.
Figure 18
Figure 20
Figure 21
Figure 22
❖ Explanation.
Figure 24
Figure 25
Figure 26
CHAPTER 2: RELATIONSHIPS BETWEEN CLASSES.
I. Association.
❖ Association is a “has-a” type relationship. Association establishes the relationship b/w two
classes using through their objects. Association relationship can be one to one, One to
many, many to one and many to many.
❖ For example, suppose we have two classes such as Student and Teacher then these two
classes are said to be “has-a” relationship if both entities share each other’s object for
some work and at the same time they can exists without each other’s dependency, or
both have their own lifetime.
Figure 27
Figure 28
Figure 29
Figure 30
Figure 31
II. Composition.
❖ Composition is a "part-of" relationship. Simply composition means mean use of
instance variables that are references to other objects. In composition relationship
both entities are interdependent of each other for example “engine is part of car”,
“heart is part of body”.
❖ For example, Between House and rooms. House can contain multiple rooms. There is
no independent life of room, and any room cannot belong to two different houses if
we delete the house room will automatically delete. Each class referenced is part-of
the aggregate class.
Figure 32
Figure 33
Figure 34
Figure 35
III. Aggregation.
❖ Aggregation is based is on "has-a" relationship. Aggregation is a special form of
association. In association there is not any classes (entity) work as owner but in
aggregation one entity work as owner. In aggregation both entities meet for some
work and then get separated. Aggregation is a one-way association.
❖ For example, let us take an example of “Student” and “Teacher”. Each student must
have an address so relationship between Student class and Teacher class will be “has-
a” type relationship. So, Teacher work as owner entity. This will be an aggregation
relationship.
Figure 36
Figure 37
Figure 38
Figure 39
Figure 40
Example:
Figure 41
Figure 42
Figure 43
Figure 44
CHAPTER 3 : DESIGN AND BUILD CLASS DIAGRAMS USING A UML
TOOL.
I. UML Class Diagram:
Figure 45