public class NarcoticDeckController extends SolitaireReleasedAdapter - PowerPoint PPT Presentation

About This Presentation
Title:

public class NarcoticDeckController extends SolitaireReleasedAdapter

Description:

public class NarcoticDeckController extends SolitaireReleasedAdapter { Solitaire ... Deck d = (Deck) narcoticGame.getModelElement('deck' ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 3
Provided by: defau635
Category:

less

Transcript and Presenter's Notes

Title: public class NarcoticDeckController extends SolitaireReleasedAdapter


1
Design Criteria Independence Enable independent
controllers to be written for independent moves
// Initialize Controllers for DeckView deckView.se
tMouseAdapter( new ResetDeckController (
new DealFourController (this, new
SolitaireReleasedAdapter(this))))
// Initialize Controllers for DeckView deckView.se
tMouseAdapter(new NarcoticDeckController (this))
Original
public class NarcoticDeckController extends
SolitaireReleasedAdapter Solitaire
narcoticGame null public
NarcoticDeckController(Solitaire game)
super(game) narcoticGame game
public void mousePressed
(java.awt.event.MouseEvent me) // Find
the deck from our model Deck d (Deck)
narcoticGame.getModelElement("deck") Pile
p1 (Pile) narcoticGame.getModelElement("pile1")
Pile p2 (Pile) narcoticGame.getModelEleme
nt("pile2") Pile p3 (Pile)
narcoticGame.getModelElement("pile3") Pile
p4 (Pile) narcoticGame.getModelElement("pile4")
if (!d.empty()) // Deal four
cards Move m new DealFourMove(d, p1,
p2, p3, p4) if (m.doMove(narcoticGame))
// SUCCESS have solitaire game
store this move narcoticGame.pushMove(
m) // have solitaire game refresh
widgets that were affected
narcoticGame.refreshWidgets()
else // Must be a request to reset the
deck. Move m new ResetDeckMove (d, p1,
p2, p3, p4) if (m.doMove(narcoticGame))
// SUCCESS
narcoticGame.pushMove (m) // refresh
all widgets that were affected by this move.
narcoticGame.refreshWidgets()

Decorated Design
2
Design Criteria Singleton Useful when exactly
one object is needed to coordinate actions across
the system
Enable anyone at anytime to access core logic
(GLOBAL)
Pros Ease of programming Cons Cannot be used to
implement a Java interface (i.e.,
IProcessMessage)
public class UserManager public static
boolean authorize(String u, String p) //
validate (u,p) combination is valid
Enable anyone at anytime to access core logic
(GLOBAL)
Pros Restrict to a single instance Cons
Introduces state into a global system
Unanticipated challenge with testing
public class UserManager / The singleton
instance. / private static UserManager inst
null / Deny any attempt to construct
outside of class. / private UserManager()
/ Method to construct or return singleton
instance. / public static UserManager
getInstance() if (inst null)
inst new UserManager() return
inst public boolean authorize(String u,
String p) // validate (u,p) combination
is valid
Write a Comment
User Comments (0)
About PowerShow.com