0% found this document useful (0 votes)
12 views27 pages

Week6 fromUMLtoCode

Uploaded by

Yu Won
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views27 pages

Week6 fromUMLtoCode

Uploaded by

Yu Won
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Software Engineering

Week 6
Software Engineering
Wk Lecture Practical
1 Introduction Canvas, Assessment Understand the case study.
Software lifecycle Write the user stories.
Design the database and the
2 Work as a group! Agile
software
Plan the work on the UI Review of the software requirements and
Set the version control
and the Use Case design
diagram. Review of the OOP concepts.
3 User Stories Git

4 Plan the work on the Graphical User Interface. MVC pattern. Coding
user stories Retrospective
Check if you are on track.
5 Plan the work on the Create and connect the database to the
database application.
From UML to C# code
6 Plan the current task Testing

7-9 Retrospective. Design patterns More coding.


Plan the current task. Accomplish the quality.
Secure coding.
10 Software Validation and Verification Double check.
No new features.
Software Maintenance.
11 Enhancements.
Software Management.
12 Review Presentation
Learning Outcomes

Understand the OOP principles.


Understand the importance of the design when it comes
to implementation.

Use a software development environment supporting the


development of computer programs to develop a
software application.
From UML Class Diagram to C# code

The UML classes from the Class Diagram describe how


the C# classes look like.

The UML associations between classes describe how the


classes interact to each other.
UML class to C# class

• A UML class becomes a C# class.


• The attributes of a UML class become variables in the
equivalent C# class.
• The operations of a UML class become methods in the
equivalent C# class.
Class Diagram - Restaurant Example
UML class to C# class
Example
UML class MenuItem Equivalent C# class

class MenuItem {
// attributes
private string itemName;
private double itemPrice;
}
UML class to C# class

Example
UML class Menu

Equivalent C# class
class Menu{
private string title;
public void addMenuItem(MenuItem menuItem) {
......
}
}
UML class to C# class – Activity 1

Example
Write the C# classes for the following two classes

Pet Owner
Name:string
name:string 1..* 1
Address:string
age:int
phoneNo:string
eat()
play(time:int) feedPet(food:string)
cleanPet()
playWithPet(time:int)
The relationships between classes

The associations, aggregations and compositions are


implemented as attributes with a user type instead of a
simple type.
The inheritance is implemented as a generalisation.
Association between classes
Teacher Pupil
name:string
1 * name:string
teach(List<Pupil> pupils) meetingWith(Teacher teacher)

Association with the multiplicity 1-*.


A Teacher teaches a group of Pupils.
A Pupil has meetings with his/her Teacher.
Association between classes
Teacher Pupil
name:string
1 * name:string
teach(List<Pupil> pupils) meetingWith(Teacher teacher)

The method teach() from class Teacher uses a list of


objects Pupil.

public class Teacher{


// attributes
private string name;

public void teach(List<Pupil> pupils) { … }


}
Association between classes
Teacher Pupil
name:string
1 * name:string
teach(List<Pupil> pupils) meetingWith(Teacher teacher)

The method meetingWith() from class Pupil uses an object


Teacher.

public class Pupil{


// attributes
private string name;

public void meetingWith(Teacher teacher) { … }


}
UML class to C# class – Activity 2
public class Pet{ public class Person{
// attributes // attributes
private string name; private string name;
private int age; private string address;
} private string phoneNo;

Pet Person

1..* 1 name:string
name:string
address:string
age:int
phoneNo:string

eat()
play(time:int) feedPet(food:string)
cleanPet()
playWithPet(time:int)
Aggregation between classes
Car Wheel
manufacturer:string 0-4 brand:string
stop()

Aggregation with the multiplicity 0-4.

An object of type Wheel belongs to one object of type Car.


A car has a maximum of 4 wheels.
A wheel can belong to more than one cars and it can exist
independently of the car.
Aggregation between classes

We add to the class Car a list of objects of type Wheel.

public class Car{


// attributes
private List<Wheel> wheels;
private string manufacturer;

public Car(List<Wheel> wheels) {


this.wheels = wheels;
}

}
UML class to C# class – Activity 3

Example
Write the C# code for the relationship between the classes

Pet Owner

name:string name:string
1..* 1
age:int
feedPet(food:string)
cleanPet()
eat()
playWithPet(time:int)
play(time:int)
UML class to C# class – Activity 3
public class Pet{ public class Owner{
// attributes // attributes
private string name; private string name;
private int age; private List<Pet> petList;
}
public Owner(List<Pet>
petList){
this.petList = petList;
}
}

Pet Owner

name:string name:string
1..* 1
age:int
feedPet(food:string)
cleanPet()
eat()
playWithPet(time:int)
play(time:int)
Composition between classes
Client BankAccount
name:string 1 amount:double
checkBalance() checkAccountBalance()

Composition with the multiplicity 1.


An object of type BankAccount belongs to one object of type
Client. If the client is removed, the bank account is also
removed.
A client has one bank account.
Composition between classes

We add to the class Client an object of type BankAccount.

public class Client{


// attributes
private BankAccount acc;
private string name;

public Client() {
acc = new BankAccount();
}
public double checkBalance() {
return acc.checkAccountBalance();
}

}
UML class to C# class – Activity 4

Example
Write the C# code for the relationship between the classes

Schedule Student
1..* name:string
time:string
UML class to C# class – Activity 3
public class Schedule{ public class Student{
// attributes // attributes
private string time; private string name;
} private List<Schedule>
scheduleList;

public Student() {
scheduleList = new
List<Schedule>();
}

Schedule Student
1..* name:string
time:string
Inheritance

An inheritance represents an "Is-a" relationship and is


modelled as a solid arrow from the subclass to the
superclass.
Attributes, operations, and associations are inherited by the
subclass from the superclass.
Inheritance

The figure shows the form of the inheritance relationship. In


this diagram we see that Wine derives from (inherits)
MenuItem.

superclass

Inheritance

subclass
Inheritance

C# code:

// class Wine inherits class MenuItem


class Wine : MenuItem {
double size;
}

The inheritance is implemented by adding a colon ":" after the


subclass name, followed by the superclass name.

Note: C# supports single class inheritance only. Therefore, you


can specify only one superclass to inherit from.
Inheritance

What attributes has the class Wine?

size

itemName
Inherited from the superclass
itemPrice MenuItem
Questions

You might also like