Presentation is loading. Please wait.

Presentation is loading. Please wait.

Abteilung für Telekooperation Video Shop Case Übung Softwareentwicklung 2 für Wirtschaftsinformatik Ismail Khalil Ibrahim Wieland Schwinger.

Similar presentations


Presentation on theme: "Abteilung für Telekooperation Video Shop Case Übung Softwareentwicklung 2 für Wirtschaftsinformatik Ismail Khalil Ibrahim Wieland Schwinger."— Presentation transcript:

1 Abteilung für Telekooperation Video Shop Case Übung Softwareentwicklung 2 für Wirtschaftsinformatik Ismail Khalil Ibrahim Wieland Schwinger

2 Abteilung für Telekooperation Development Process Disclaimer: –These slided present a Video Shop example case –The shown succeeding steps present not the ultimative development process rather they represent one way - intentionally including some straight forward development steps - how to derive at a solution In general the development of a system can follow two dimensions: 1) horizontally: staying at the same level of abstraction expanding the model to capture additional parts of the system 2) vertically: going towards implementation extending the model towards a deeper level of detail by adding design details Analysis Design Implementation covering more requirements

3 Abteilung für Telekooperation Case Study: Video Shop - Requirements Accounting of a video shop: –3 Types of video films normal priced videos € 2 + € 1, 50 per day from 3 rd day on newly released videos € 3 per day children videos € 1, 50 + € 1, 50 per day from 4 th day on –Bonus points per rental normal priced videos1 point newly released videos 1 point + 1 additional point, from 2 nd day on children videos 1 point Required output: Customer: Max Glotzmann // customer Star Trek3,50 Terminator VII6,00 Lion King3,00 Overall price 12,50 // overall price Bonus points4 // bonus points

4 Abteilung für Telekooperation Case Study: Video Shop - Requirements Customers rent video films Accounting of a video shop: –3 Types of video films normal priced videos € 2 + € 1, 50 per day from 3 rd day on newly released videos € 3 per day children videos € 1, 50 + € 1, 50 per day from 4 th day on –Bonus points per rental normal priced videos1 point newly released videos 1 point + 1 additional point, from 2 nd day on children videos 1 point 0. step Customer rent some movies. For each customer an invoice should generated containing the overall price and the bonus points. Customer are identified by their name. Movies have different titles. There exists three types of movies.

5 Abteilung für Telekooperation Analysis Movie title kind Customer name makeInvoice() addRental() 0..* rents 0..1 1. step Customer rent some movies. For each customer an invoice should generated. Customer are identified by their name. Movies have different titles. There exists three types of movies. 3 Types of video films normal priced videos: € 2 + € 1,50 per day from 3rd day on newly released videos: € 3 per day children videos: € 1,50 + € 1,50 per day from 4th day on Customer rent some movies.

6 Abteilung für Telekooperation Analysis Movie title kind Customer name makeInvoice() 0..* rents 0..1 Movie title kind Rental days Customer name makeInvoice() addRental() 0..* rents 0..1 1. step 2. step normal priced videos: € 2 + € 1,50 per day from 3rd day on newly released videos: € 3 per day children videos: € 1,50 + € 1,50 per day from 4th day on

7 Abteilung für Telekooperation Design Movie - title - kind Rental - days Customer - name : String + getName() : String + setName(name : String) : void + addRental(rental : Rental) : void + makeInvoice() : String 0..* rents 0..1 3. step getTitle() setTitle(title : String) setKind(kind : int) getKind() : int getMovie() : Movie getDays() : int adding visibility, adding get/set-methods adding data types kind must be is either Movie.regular or Movie.children or Movie.newRelease

8 Abteilung für Telekooperation Class "Customer" (Kunde) 4. step -> transcription into Java of class "Customer" class Customer { private String name; private List rents = new LinkedList (); public Customer (String name) { this.name = name; } public String getName () { return name; } public void setName (String name) { this.name = name; } public void addRental (Rental rental) { rents.add(rental); } public String makeInvoice () { // liefert einen Rechnungstext über alle ausgeliehenen Filme // hier steckt die gesamte Steuerlogik! } 1 : n relationship rents

9 Abteilung für Telekooperation Class "Rental" (Ausleihung) 5. step -> transcription into Java of class "Rental" class Rental { private Movie movie; private int days; public Rental (Movie movie, int days) { this.movie = movie; this.days = day; } public Movie getMovie () { return movie; } public int getDays () { return days; } }

10 Abteilung für Telekooperation Class "Movie" (Filme) class Movie { private String title; private MovieKind kind; public Movie (Sting s, int n) { title = s; kind = n; } public String getTitle () { return title; } public void setKind (int n) { kind = n; } public int getKind () { return kind; } } public enum MovieKind { REGULAR, NEWRELEASE, CHILDREN; } 6. step -> transcription into Java of class "Movie" Movie - title - kind getTitle() setTitle(title : String) setKind(kind : int) getKind() : int

11 Abteilung für Telekooperation Class "Customer" : makeInvoice() public String makeInvoice () { int price = 0, total = 0, bonus = 0; // Preise in Euro-Cent Iterator films = rents.iterator(); StringBuffer sb = new StringBuffer("Kunde: " + name + "\n"); while (films.hasNext()) { Rental r = (Rental) films.next(); int kind = r.getMovie().getKind(), days = r.getDays(); switch (kind) { case REGULAR: price = 200; if (days > 2) price += (days - 2) * 150; break; case NEWRELEASE: price = days * 300; break; case CHILDREN: price = 150; if (days > 3) price += (days - 3) * 150; break; } bonus++; if (kind == Movie.newRelease && days > 1) bonus++; sb.append("\t" + r.getMovie().getTitle() + "\t"); sb.append(price/100 + "," + price %100 + "\n"); total += price; } sb.append("\nGesamtbetrag:\t"+ total/100 + "," + total%100); sb.append("\nBonuspunkte:\t" + bonus); return sb.toString(); } 7. step -> specifying the method makeInvoice() of class Customer

12 Abteilung für Telekooperation computeBonusFor (Rental r) Class "Customer": makeInvoice() decomposed public String makeInvoice () { int price = 0, total = 0, bonus = 0; Iterator films = rental.iterator(); StringBuffer sb = new StringBuffer("Kunde: " + name); while (films.hasNext()) { Rental r = (Rental) films.next(); int kind = r.getMovie().getKind(), days = r.getDays(); switch (kind) { case Movie.REGULAR: price = 200; if (days > 2) price += (days - 2) * 150; break; case Movie.NEWRELEASE: price = days * 300; break; case Movie.CHILDREN: price = 150; if (days > 3) price += (days - 3) * 150; break; } bonus++; if (kind == Movie.newRelease && days > 1) bonus++; sb.append("\t" + r.getMovie().getTitle() + "\t"); sb.append(price/100 + "," + price %100 + "\n"); total += price; } sb.append("\nGesamtbetrag:\t"+ total/100 + "," + total%100); sb.append("\nBonuspunkte:\t" + bonus); return sb.toString(); } extract code from the method makeInvoice() of class "Customer" computeChargeFor(Rental r)

13 Abteilung für Telekooperation Class "Customer": computeChargeFor(r)/computeBonusFor(r) public int computeChargeFor (Rental r) { int price = 0; int kind = r.getMovie().getKind(), days = r.getDays(); switch (kind) { case Movie.REGULAR: price = 200; if (days > 2) price += (days - 2) * 150; break; case Movie.NEWRELEASE: price = days * 300; break; case Movie.CHILDREN: price = 150; if (days > 3) price += (days - 3) * 150; break; } return price; } public int computeBonusFor (Rental r) { return (r.getMovie().getKind() == Movie.newRelease && r.getDays() > 1) ? 1 : 2; } 8. step -> extract code from the method makeInvoce of class "Customer" by adding to additional methods to the class "Customer" responsible for the calculation of the price and the bonus

14 Abteilung für Telekooperation Class "Customer": makeInvoice() NEW BUT: computeChargeFor/computeBonusFor relate to "Rental" rather then "Customer" ==> methods should be moved to class "Rental" instead public String makeInvoice () { int price = 0, total = 0, bonus = 0; // Preise in Euro-Cent Iterator films = rental.iterator(); StringBuffer sb = new StringBuffer("Kunde: " + name); while (films.hasNext()) { Rental r = (Rental) films.next(); price = computeChargeFor(r); // method of class Customer to compute the charge of a rental bonus += computeBonusFor(r); // method of class Customer to compute the bonus of a rental sb.append("\t" + r.getMovie().getTitle() + "\t"); sb.append(price/100 + "," + price %100 + "\n"); total += price; } sb.append("\nGesamtbetrag:\t"+ total/100 + "," + total%100); sb.append("\nBonuspunkte:\t" + bonus); return sb.toString(); }

15 Abteilung für Telekooperation Revised Model (1) 9. step -> consequently the two methods realized within the class "Rental" instead of the class "Customer" Movie - title - kind Rental - days Customer - name : String + getName() : String + setName(name : String) : void + addRental(rental : Rental) : void + makeInvoice() : String 0..* rents 0..1 getTitle() setTitle(title : String) setKind(kind : int) getKind() : int getMovie() : Movie getDays() : int getCharge() : int getBonus() : int

16 Abteilung für Telekooperation public String makeInvoice () {... price = r.getCharge(); bonus += r.getBonus();... } Class "Rental": getCharge / getBonus () BUT: getCharge/getBonus refer to the object movie ==> deligate behaviour to the class movie and pass only the days as parameter?! public int getBonus () { return (movie.getKind() == Movie.newRelease && days > 1) ? 1 : 2; } public int getCharge () { int price = 0; int kind = movie.getKind(); switch (kind) { case REGULAR: price = 200; if (days > 2) price += (days - 2) * 150; break; case NEWRELEASE: price = days * 300; break; case CHILDREN: price = 150; if (days > 3) price += (days - 3) * 150; break; } return price; }

17 Abteilung für Telekooperation Revised Model (2) Movie - title - kind Rental - days Customer - name : String + getName() : String + setName(name : String) : void + addRental(rental : Rental) : void + makeInvoice() : String 0..* rents 0..1 getTitle() setTitle(title : String) setKind(kind : int) getKind() : int getCharge(days) : int getBonus(days) : int getMovie() : Movie getDays() : int getCharge() : int getBonus() : int 8. step -> moving the logics of getCharge/getBonus into the class "Movie"

18 Abteilung für Telekooperation public int getCharge() { return movie.getCharge(days); } public int getBonus () { return movie.getBonus(days); } Class "Movie": getCharge / getBonus (days) public int getCharge (int days) { int price = 0; switch (kind) { case REGULAR: price = 200; if (days > 2) price += (days - 2) * 150; break; case NEWRELEASE: price = days * 300; break; case CHILDREN: price = 150; if (days > 3) price += (days - 3) * 150; break; } return price; } public int getBonus (int days) { return (kind == newRelease && days > 1) ? 1 : 2; } BUT: getCharge/getBonus currently are not exploiting dynamic binding to make the case decisions ==> sub-classing of three different sub- types: RegularMovie, NewMovie, and ChildrenMovie

19 Abteilung für Telekooperation Revised Model Exploiting Dynamic Binding RegularMovie getCharge(days):int NewMovie getCharge(days):int getBonus(days):int ChildrenMovie getCharge(days):int NOTE: even more flexibility can be achieved if the class model is developed further to a framework by applying a construct like the Strategy Pattern. Movie - title - kind Rental - days Customer - name : String + getName() : String + setName(name : String) : void + addRental(rental : Rental) : void + makeInvoice() : String 0..* rents 0..1 getTitle() setTitle(title : String) setKind(kind : int) getKind() : int getCharge(days) : int getBonus(day) : int getMovie() : Movie getDays() : int getCharge() : int getBonus() : int 8. step -> making class "Movie" abstract and adding three different sub-classes

20 Abteilung für Telekooperation Framework with Hot-Spot "Price" Movie - title - kind Rental - days Customer - name : String + getName() : String + setName(name : String) : void + addRental(rental : Rental) : void + makeInvoice() : String 0..* rents 0..1 getTitle() setTitle(title : String) setKind(kind : int) getKind() : int getCharge(days) : int getBonus(days) : int getMovie() : Movie getDays() : int getCharge() : int getBonus() : int RegularPrice getCharge(days):int NewPrice getCharge(days):int getBonus(days):int ChildrenPrice getCharge(days):int Price getCharge(days) : int getBonus(days) : int 1 pricing 0..* 9. step -> additional flexibility by adding a class Price responsible for the pricing strategy acting as framework hot-spot

21 Abteilung für Telekooperation Class "Price" and its Sub-Classes abstract class Price { public abstract int getCharge (int days); public int getBonus (int days) { return 1; } } class RegularPrice extends Price { public int getCharge (int days) { if (days > 2) return 200 + (days-2)*150; else return 200; } class NewPrice extends Price { public int getCharge (int days) { return days * 300; } public int getBonus (int days) { if (days > 1) return 2; else return 1; } class ChildPrice extends Price { public int getCharge (int days) { if (days > 3) return 150 + (days-3)*150; else return 150; }

22 Abteilung für Telekooperation Implementation of Class "Movie" class Movie { private String title; private Price pricing; public Movie (String title, Price price) { this.title = title; this.price = price; } public String getTitle () { return title; } public String setTitle (String title) { this.title = title; } public void setPrice (Price p) { pricing = p; } public Price getPrice () { return price; } public int getCharge (int days) { return pricing.getCharge(days); } public int getBonus (int days) { return pricing.getBonus(days); } }

23 Abteilung für Telekooperation Implementation of Class "Customer" class Customer { private String name; private List rents = new LinkedList(); public Customer (String name) { this.name = name; } public void addRental (Rental r) { rents.add(r); } public String makeInvoice () { int price = 0, total = 0, bonus = 0; Iterator films = rents.iterator(); StringBuffer sb = new StringBuffer("Kunde: " + name + "\n"); while (films.hasNext()) { Rental r = (Rental) films.next(); price = r.getCharge(); bonus += r.getBonus(); sb.append("\t" + r.getMovie().getTitle() + "\t"); sb.append(price/100 + "," + price %100 + "\n"); total += price; } sb.append("\nGesamtbetrag:\t"+ total/100 + "," + total%100); sb.append("\nBonuspunkte:\t" + bonus); return sb.toString(); }

24 Abteilung für Telekooperation Implementation of Class "Rental" class Rental { private Movie movie; private int days; public Rental (Movie movie, int days) { this.movie = movie; this.days = days; } public Movie getMovie () { return movie; } public int getDays () { return days; } public int getCharge () { return movie.getCharge(days); } public int getBonus () { return movie.getBonus(days); } }

25 Abteilung für Telekooperation Implementation of Class "Movie" class Movie { private String title; private Price pricing; public Movie (String title, Price price) { this.title = title; this.price = price; } public String getTitle () { return title; } public String setTitle (String title) { this.title = title; } public void setPrice (Price p) { pricing = p; } public Price getPrice () { return price; } public int getCharge (int days) { return pricing.getCharge(days); } public int getBonus (int days) { return pricing.getBonus(days); } }

26 Abteilung für Telekooperation Implementation of Class "Price" abstract class Price { public abstract int getCharge (int days); public int getBonus (int days) { return 1; } } class RegularPrice extends Price { public int getCharge (int days) { if (days > 2) return 200 + (days-2)*150; else return 200; } class NewPrice extends Price { public int getCharge (int days) { return days * 300; } public int getBonus (int days) { if (days > 1) return 2; else return 1; } class ChildPrice extends Price { public int getCharge (int days) { if (days > 3) return 150 + (days-3)*150; else return 150; }

27 Abteilung für Telekooperation Video Shop Application (1/2) class VideoApp { public static final Price regular = new RegularPrice(); public static final Price newRelease = new NewPrice(); public static final Price children = new ChildPrice(); private Map customers = new HashMap(); private Map movies = new HashMap(); void addMovie (Movie movie) { movies.put(movie.getName(), movie); } void addCustomer (Customer customer) { customers.put(customer.getName(), customer); } public static void main (String[] args) {... }

28 Abteilung für Telekooperation Video Shop Application (2/2) class VideoApp {... public static void main (String[] args) { VideoApp bb = new VideoApp(); // bb … Blockbuster Customer mg = new Customer("Max Glotzmann"); bb.addCustomer(mg); Movie m1 = new Movie("Star Trek", regular), m2 = new Movie("Terminator VII", newRelease); m3 = new Movie("Lion King", children); bb.addMovie(m1); bb.addMovie(m2); bb.addMovie(m3); mg.addRental(new Rental(m1, 3)); mg.addRental(new Rental(m2, 2)); mg.addRental(new Rental(m3, 4)); System.out.println(mg.makeInvoice()); }


Download ppt "Abteilung für Telekooperation Video Shop Case Übung Softwareentwicklung 2 für Wirtschaftsinformatik Ismail Khalil Ibrahim Wieland Schwinger."

Similar presentations


Ads by Google