Skip to content

A coinpurse class simulate coin and purse that can be put or withdraw the coins in purse.

Notifications You must be signed in to change notification settings

guitarpawat/coinpurse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CoinPurse

CoinPurse simulate monetary objects and Purse by using inheritance and polymorphism.

Polymorphism

Polymorphism can be used when one task perform in different ways in many class. Sometimes, it like a draft for the classes.

Inheritance

You can use methods and variables from superclass in subclasses if it is not private and can override if it is not final.

Abstract class

Abstract classes is like an interface but you can write some codes to use it in subclasses without writing the same code in each class again.

Observer

Purse class has extends Observable, so you can create any class to receive the event when it's fire. You can create and add the observer to the Main class.

Strategy

Purse class can set WithdrawStrategy for select how to withdraw the money from purse. There are two WithdrawStrategy class for Purse :

  1. GreedyWithdraw is the strategy by withdraw money from highest value first. This strategy can be use in most case, but not all.
  2. RecursiveWithdraw is the strategy that looking all possible way to withdraw money, this may consume much memory and caused stack overflow.

All two strategies are implements WithdrawStrategy, so you can create more strategy to use it in Purse and set the strategy by using setStrategy() method in Purse.

About

A coinpurse class simulate coin and purse that can be put or withdraw the coins in purse.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages