Session 6 Video Shop Case - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Session 6 Video Shop Case

Description:

Terminator VII 6,00. Lion King 3,00. Overall price 12,50 // overall price ... Customer rent some movies. ... Customer rent some movies. For each customer an ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 29
Provided by: ismailkhal
Category:
Tags: case | session | shop | video

less

Transcript and Presenter's Notes

Title: Session 6 Video Shop Case


1
Session 6Video Shop Case
Übung Softwareentwicklung 2für
Wirtschaftsinformatik
Ismail Khalil IbrahimWieland Schwinger
2
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

covering more requirements
Analysis
Design
Implementation
3
Case Study Video Shop - Requirements
  • Accounting of a video shop
  • 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
  • Bonus points per rental
  • normal priced videos 1 point
  • newly released videos 1 point 1 additional
    point, from 2nd day on
  • children videos 1 point
  • Required output

Customer Max Glotzmann // customer Star
Trek 3,50 Terminator VII 6,00 Lion
King 3,00 Overall price 12,50 //
overall price Bonus points 4 // bonus points
4
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
    3rd day on
  • newly released videos 3 per day
  • children videos 1,50 1,50 per day from 4th
    day on
  • Bonus points per rental
  • normal priced videos 1 point
  • newly released videos 1 point 1 additional
    point, from 2nd 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
Analysis
1. step
0..1
0..
rents
Movie
Customer
title kind
name
Customer rent some movies.
Customer rent some movies.
makeInvoice() addRental()
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
For each customer an invoice should generated.
Customer are identified by their name.
6
Analysis
1. step
0..1
0..
rents
Movie
Customer
title kind
name
makeInvoice()
2. step
0..1
0..
rents
Movie
Customer
title kind
name
makeInvoice() addRental()
Rental
days
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
Design
3. step
0..1
0..
rents
Movie
Customer
- title - kind
- name String
getName() String setName(name String)
void addRental(rental Rental) void
makeInvoice() String
Rental
getTitle() setTitle(title String) setKind(kind
int) getKind() int
- days
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
Class "Customer" (Kunde)
  • 4. step -gt 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
Class "Rental" (Ausleihung)
  • 5. step -gt 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
Class "Movie" (Filme)
  • 6. step -gt transcription into Java of class
    "Movie"

Movie
- title - kind
class Movie public static final int REGULAR
0, NEWRELEASE 1,
CHILDREN 2 private
String title private int 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
getTitle() setTitle(title String) setKind(kind
int) getKind() int
11
Class "Customer" makeInvoice()
7. step -gt specifying the method makeInvoice() of
class Customer
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 Movie.REGULAR price 200 if
(days gt 2) price (days - 2) 150
break case Movie.NEWRELEASE price days
300 break case Movie.CHILDREN price
150 if (days gt 3) price
(days - 3) 150 break bonus if
(kind Movie.newRelease days gt 1) bonus
sb.append("\t" r.getMovie().getTitle()
"\t") sb.append(price/100 "," price 100
"\n") total price
sb.append("\nGesamtbetrag\t" total/100 ","
total100) sb.append("\nBonuspunkte\t"
bonus) return sb.toString()
12
Class "Customer" makeInvoice() decomposed
  • extract code from the method makeInvoice() of
    class "Customer"

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 gt 2) price (days - 2) 150
break case Movie.NEWRELEASE price days
300 break case Movie.CHILDREN price
150 if (days gt 3) price
(days - 3) 150 break bonus if
(kind Movie.newRelease days gt 1) bonus
sb.append("\t" r.getMovie().getTitle()
"\t") sb.append(price/100 "," price 100
"\n") total price
sb.append("\nGesamtbetrag\t" total/100 ","
total100) sb.append("\nBonuspunkte\t"
bonus) return sb.toString()
13
Class "Customer" computeChargeFor(r)/computeBonus
For(r)
8. step -gt 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
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 gt
2) price (days - 2) 150 break
case Movie.NEWRELEASE price days 300
break case Movie.CHILDREN price 150
if (days gt 3) price (days - 3)
150 break return price
public int computeBonusFor (Rental r) return
(r.getMovie().getKind() Movie.newRelease
r.getDays() gt 1) ? 1 2
14
Class "Customer" makeInvoice() NEW
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 ","
total100) sb.append("\nBonuspunkte\t"
bonus) return sb.toString()
  • BUT computeChargeFor/computeBonusFor relate to
    "Rental" rather then "Customer"
  • gt methods should be moved to class
    "Rental" instead

15
Revised Model (1)
9. step -gt consequently the two methods realized
within the class "Rental" instead of the class
"Customer"
0..1
0..
rents
Movie
Customer
- title - kind
- name String
getName() String setName(name String)
void addRental(rental Rental) void
makeInvoice() String
Rental
getTitle() setTitle(title String) setKind(kind
int) getKind() int
- days
getMovie() Movie getDays() int getCharge()
int getBonus() int
16
Class "Rental" getCharge / getBonus ()
BUT getCharge/getBonus refer to the object movie
gt deligate behaviour to the class movie and
pass only the days as parameter?!
17
Revised Model (2)
8. step -gt moving the logics of
getCharge/getBonus into the class "Movie"
0..1
0..
rents
Movie
Customer
- title - kind
- name String
getName() String setName(name String)
void addRental(rental Rental) void
makeInvoice() String
Rental
getTitle() setTitle(title String) setKind(kind
int) getKind() int getCharge(days)
int getBonus(days) int
- days
getMovie() Movie getDays() int getCharge()
int getBonus() int
18
Class "Movie" getCharge / getBonus (days)
BUT getCharge/getBonus currently are not
exploiting dynamic binding to make the case
decisions gt sub-classing of three different
sub-types RegularMovie, NewMovie, and
ChildrenMovie
19
Revised Model Exploiting Dynamic Binding
8. step -gt making class "Movie" abstract and
adding three different sub-classes
0..
rents
0..1
Movie
Customer
- title - kind
- name String
getName() String setName(name String)
void addRental(rental Rental) void
makeInvoice() String
Rental
getTitle() setTitle(title String) setKind(kind
int) getKind() int getCharge(days)
int getBonus(day) int
- days
getMovie() Movie getDays() int getCharge()
int getBonus() 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.
20
Framework with Hot-Spot "Price"
9. step -gt additional flexibility by adding a
class Price responsible for the pricing strategy
acting as framework hot-spot
0..1
0..
rents
Movie
Customer
- title - kind
- name String
Rental
getName() String setName(name String)
void addRental(rental Rental) void
makeInvoice() String
- days
getTitle() setTitle(title String) setKind(kind
int) getKind() int getCharge(days)
int getBonus(days) int
getMovie() Movie getDays() int getCharge()
int getBonus() int
21
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 gt 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 gt 1) return 2 else return 1 class
ChildPrice extends Price public int getCharge
(int days) if (days gt 3) return 150
(days-3)150 else return 150
22
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
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("\nGesamtb
etrag\t" total/100 "," total100)
sb.append("\nBonuspunkte\t" bonus) return
sb.toString()
24
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
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
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 gt 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 gt 1) return 2 else return 1 class
ChildPrice extends Price public int getCharge
(int days) if (days gt 3) return 150
(days-3)150 else return 150
27
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
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())
Write a Comment
User Comments (0)
About PowerShow.com