Title: Video Shop Case
1Video Shop Case
Übung Softwareentwicklung 2für
Wirtschaftsinformatik
Ismail Khalil IbrahimWieland Schwinger
2Development 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
3Case 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
4Case 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.
5Analysis
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.
6Analysis
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
7Design
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
8Class "Customer" (Kunde)
- 4. step -gt transcription into Java of class
"Customer"
class Customer private String name private
ListltRentalgt rents new LinkedListltRentalgt()
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
9Class "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
10Class "Movie" (Filme)
- 6. step -gt transcription into Java of class
"Movie"
Movie
- title - kind
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
getTitle() setTitle(title String) setKind(kind
int) getKind() int
11Class "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 REGULAR price 200 if (days gt
2) price (days - 2) 150 break
case NEWRELEASE price days 300 break
case 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()
12Class "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()
13Class "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
14Class "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
15Revised 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
16Class "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?!
17Revised 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
18Class "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
19Revised 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.
20Framework 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
21Class "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
22Implementation 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)
23Implementation 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()
24Implementation 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)
25Implementation 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)
26Implementation 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
27Video 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) ...
28Video 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())