Pobieranie prezentacji. Proszę czekać

Pobieranie prezentacji. Proszę czekać

Inheritance mapping from UML to C#.

Podobne prezentacje


Prezentacja na temat: "Inheritance mapping from UML to C#."— Zapis prezentacji:

1 Inheritance mapping from UML to C#

2 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Plan of a presentation Introduction Disjoint inheritance Overlapping inhritance Complete inheritance Incomplete inheritance Multi-inheritance Multi-aspect inheritance Dynamic inheritance Tasks MAS Wojciech Gorzkowski & Michał Juchnowicz

3 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Introduction Generalization – specialization a relationship that connects so called superclass with another classes that are called subclasses. Person Osoba specjalizacja generalizacja Employee Pracownik Assistant Tutor Reader Professor Asystent Adiunkt Docent Profesor MAS Wojciech Gorzkowski & Michał Juchnowicz

4 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Introduction Superclass is more general than its subclasses. Sometimes it is said, that superclass is a generalization of a subclass and subclass is a specialization of a superclass. Inheritance Its mechanism is strictly related to the specialization – generalization relationship. Thanks to inheritance class invariants are imported from the superclass to the subclasses. It means that subclass has all properties its superclass; moreover subclass can have (and usually has) also additional properties. Invariants’ inheritance is transitive MAS Wojciech Gorzkowski & Michał Juchnowicz

5 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Introduction Generalization hierarchy cannot contain a loop. It can be a grid – then it models repeating inheritance (in further part of the presentation) Person K1 K2 Student Employee K3 Student_assistant Grid Loop MAS Wojciech Gorzkowski & Michał Juchnowicz

6 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Introduction The most common mistake is that we make a class hierarchy only based on similarity of the attributes. When we make a class hierarchy we have to take into account that classes in the hierarchy have to have similar semantics. They also have to have such a property: subclass object is a special case of a superclass object (e.g. Employee is a special case of a Person object.) MAS Wojciech Gorzkowski & Michał Juchnowicz

7 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Disjoint inheritance No common point Default way of implementing For instance: Human Female Male MAS Wojciech Gorzkowski & Michał Juchnowicz

8 Overlapping inheritance
Common points Implementing couses change in diagram For instance: Building Garage House {overlapping} MAS Wojciech Gorzkowski & Michał Juchnowicz

9 Overlapping inheritance did with additional class
class Building { } class House: Building class Garage: Building class HouseWithGarage: Building Building Garage House House with garage MAS Wojciech Gorzkowski & Michał Juchnowicz

10 Overlapping inheritance did with composition
class Building { House house; Garage garage; } class House class Garage Building Garage House 0..1 MAS Wojciech Gorzkowski & Michał Juchnowicz

11 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Complete inheritance In UML diagram, complete is a default value, so it doesn’t have to be written. It means that all the subclasses were defined (all the subclasses were drawn at the diagram). For instance: Person {abstract} {complete} Student Employee MAS Wojciech Gorzkowski & Michał Juchnowicz

12 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
using System; using System.Threading; namespace CompleteInheritance { class CompleteInheritance static void Main(string[] args) Student kowalski = new Student("Jan", "Kowalski", "Wrocław", "617"); Employee nowak = new Employee("Jan","Nowak","Warszawa",1000); kowalski.getInfo(); Console.WriteLine(" "); nowak.getInfo(); } abstract class Person protected string name; protected string surname; protected string city; public Person(string name, string surname, string city) this.name = name; this.surname = surname; this.city = city; public abstract void getInfo(); MAS Wojciech Gorzkowski & Michał Juchnowicz

13 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
class Student : Person { string group; public Student(string name, string surname, string city, string group) : base(name, surname, city) this.group = group; } public override void getInfo() Console.WriteLine("I'm a student and that's my personall datas:\n" + "Name: " + this.name + "\n" + "Surname: " + this.surname + "\n" + "City: " + this.city + "\n" + "Group: " + this.group + "\n" ); Thread.Sleep(5000); class Employee : Person int salary; public Employee(string name, string surname, string city, int salary) this.salary = salary; Console.WriteLine("I'm an amployee and that's my personall datas:\n" + "Salary: " + this.salary.ToString() + "\n" MAS Wojciech Gorzkowski & Michał Juchnowicz

14 Incomplete inheritance
In UML diagram, incomplete is not a default value, so it has to be written. It means that not all the subclasses were defined. The superclass here can’t be an abstract class. It is a default inheritance inter alia in C# programming language. For instance: Dog {incomplete} Alsatian Bulldog MAS Wojciech Gorzkowski & Michał Juchnowicz

15 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
using System; using System.Threading; namespace IncompleteInheritance { class IncompleteInheritance static void Main(string[] args) Student kowalski = new Student("Jan", "Kowalski", "Wrocław", "617"); Employee nowak = new Employee("Jan","Nowak","Warszawa",1000); kowalski.getInfo(); Console.WriteLine(" "); nowak.getInfo(); } class Person protected string name; protected string surname; protected string city; public Person(string name, string surname, string city) this.name = name; this.surname = surname; this.city = city; MAS Wojciech Gorzkowski & Michał Juchnowicz

16 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
class Student : Person { string group; public Student(string name, string surname, string city, string group) : base(name, surname, city) this.group = group; } public void getInfo() Console.WriteLine("I'm a student and that's my personall datas:\n" + "Name: " + this.name + "\n" + "Surname: " + this.surname + "\n" + "City: " + this.city + "\n" + "Group: " + this.group + "\n" ); Thread.Sleep(5000); class Employee : Person int salary; public Employee(string name, string surname, string city, int salary) this.salary = salary; Console.WriteLine("I'm an amployee and that's my personall datas:\n" + "Salary: " + this.salary.ToString() + "\n" MAS Wojciech Gorzkowski & Michał Juchnowicz

17 Complete and incomplete inheritance
Complete and incomplete inheritances are used mainly in conceptual modelling. They don’t have any reference (odniesienia) in implementation. MAS Wojciech Gorzkowski & Michał Juchnowicz

18 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Multi-inheritance Inheritance from many classes at the same time C# doesn’t support multi-inheritance of classes For instance: Camera Video play() zoom() Picture flash() Photo camera Photo/Video camera Video camera MAS Wojciech Gorzkowski & Michał Juchnowicz

19 Multi-inheritance did with additional subclass
class Camera{} interface IPicture { void flash(); void zoom(); } interface IVideo void play(); class VideoCamera: Camera, IVideo public void play(){} public void zoom(){} class PhotoVideoCamera: Camera, IPicture, IVideo public void flash(){} Camera Video play() zoom() Picture flash() Photo camera Photo/Video camera Video camera MAS Wojciech Gorzkowski & Michał Juchnowicz

20 Multi-aspect inheritance
Multi-aspect inheritance – inheritance in which there are more than 1 aspect of inheritance. In this case the aspect of inheritance cannot be ommited on the UML diagram. For instance: Vehicle drive terrain Wind vehicle Engine vehicle Terrestrial vehicle Water vehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

21 Multi-aspect inheritance did with composition
Vehicle Drived vehicle Terrain Vehicle drive terrain Wind vehicle Engine vehicle Terrestrial vehicle Water vehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

22 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
using System; namespace MultiAspectInheritance { class MultiAspectInheritance static void Main(string[] args) } class Vehicle DrivedVehicle drivedVehicle; TerrainVehicle terrainVehicle; abstract class DrivedVehicle abstract class TerrainVehicle class WindVehicle : DrivedVehicle class EngineVehicle : DrivedVehicle class TerrestrialVehicle : TerrainVehicle class WaterVehicle : TerrainVehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

23 Multi-aspect inheritance did with inheritance and composition
Vehicle Drived vehicle Terrain Vehicle drive terrain Wind vehicle Engine vehicle Terrestrial vehicle Water vehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

24 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
using System; namespace MultiAspectInheritance { class MultiAspectInheritance static void Main(string[] args) } class Vehicle TerrainVehicle terrainVehicle; abstract class DrivedVehicle : Vehicle abstract class TerrainVehicle class WindVehicle : DrivedVehicle class EngineVehicle : DrivedVehicle class TerrestrialVehicle : TerrainVehicle class WaterVehicle : TerrainVehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

25 Multi-aspect inheritance did with encapsulated specification
Vehicle drive Wind vehicle Engine vehicle terrain terrain Terrestrial and wind vehicle Water and wind vehicle Terrestrial and engine vehicle Water and engine vehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

26 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
using System; namespace MultiAspectInheritance { class MultiAspectInheritance static void Main(string[] args) } abstract class Vehicle abstract class WindVehicle : Vehicle abstract class EngineVehicle : Vehicle class TerrestrialAndWindVehicle : Vehicle class WaterAndWindVehicle : Vehicle class TerrestrialAndEngineVehicle : Vehicle class WaterAndEngineVehicle : Vehicle MAS Wojciech Gorzkowski & Michał Juchnowicz

27 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Dynamic inheritance Object changes its state dynamically Substance Ice Steam Liquid <<dynamic>> MAS Wojciech Gorzkowski & Michał Juchnowicz

28 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Dynamic inheritance interface ISubstance { void changeState(); } class Liquid: ISubstance public Liquid(){} public void changeState() Console.WriteLine(„Liquid -> Ice"); class Ice: ISubstance public Ice(){} Console.WriteLine(„Ice -> Liquid"); Ice ice = new Ice(); Liquid liquid = new Liquid(); ISubstance h2o = ice; h2o.changeState(); Output: Liquid -> Ice h2o = liquid; h2o.changeState(); Output: Ice -> Liquid MAS Wojciech Gorzkowski & Michał Juchnowicz

29 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Tasks 1 A company „Krzak” selling computers needs a system that will store information about computers and palmtops. The „Krzak” sells coputers such as notebooks and desktop computers as well as such types of palmtops: with colour and monochromatic display. MAS Wojciech Gorzkowski & Michał Juchnowicz

30 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Task 2 A company „Krzak” selling computers needs a system that will store information about computers. The „Krzak” sells computers such as notebooks, desktop computers etc. MAS Wojciech Gorzkowski & Michał Juchnowicz

31 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Task 3 Car dealer „Krzak” selling cars wants to store information about available cars. The cars are divided with respect to engine (petrol, diesel) as well as equipment (air condition, audio system) MAS Wojciech Gorzkowski & Michał Juchnowicz

32 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Task 4 Company „Posprzątamy” needs a system that will store information about cleaners and owners of company. Remember that owner cannot work as a cleaner. MAS Wojciech Gorzkowski & Michał Juchnowicz

33 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Task 5 Computer company selling network devices needs a system that will store information about routers, modems and network cards. Company sells also routers with bult-in modems. MAS Wojciech Gorzkowski & Michał Juchnowicz

34 MAS 2004 Wojciech Gorzkowski & Michał Juchnowicz
Task 6 Real estate agency „Dom” needs a system that will store information about houses they have in offer. House can be empty, rented, sold or in renovation. MAS Wojciech Gorzkowski & Michał Juchnowicz


Pobierz ppt "Inheritance mapping from UML to C#."

Podobne prezentacje


Reklamy Google