A Case Study in OO Design and Team Development The Game of SET: Maria Litvin Phillips Academy Andover, Massachusetts Advance Placement Program Professional.

Slides:



Advertisements
Similar presentations
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Example - The.
Advertisements

AP Computer Science A – Healdsburg High School 1 Unit 3 - Classes and Objects - Example.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
The Model-View Approach in Java. OK, you’ve got “Hello World” running... What now?
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
1 CS1001 Lecture Overview Homework 3 Homework 3 Project/Paper Project/Paper Object Oriented Design Object Oriented Design.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
The chapter will address the following questions:
OO Analysis and Design CMPS OOA/OOD Cursory explanation of OOP emphasizes ▫ Syntax  classes, inheritance, message passing, virtual, static Most.
Abstraction, Inheritance, and Polymorphism in Java.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Topic 3 The Stack ADT.
OOD Case Study (For parallel treatment, see Chapter 2 of the text)
CPSC1301 Computer Science 1 Chapter 11 Creating Classes part 1.
Stacks and Queues Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming.
Case Study: Game2D with Method Design
CreatingClasses-part11 Creating Classes part 1 Barb Ericson Georgia Institute of Technology Dec 2009.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
The Model-View Approach in Teaching Java Maria Litvin Phillips Academy, Andover, MA
CSE 219 Computer Science III Program Design Principles.
Objects and Classes Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary.
Systems Analysis & Design 7 th Edition Chapter 5.
Systems Analysis and Design 8 th Edition Chapter 6 Object Modeling.
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
Spring, 2009Purchase College/SUNY The Set Game Jeanine Meyer Mathematics/Computer Science Senior Seminar.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Chapter 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
12 OBJECT-ORIENTED DESIGN CHAPTER
Week101 APCS-AB: Java Miscellaneous Topics: Snippets we missed in Chapters 1-6 of book November 11, 2005.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Chapter 12 – Object-Oriented Design
Observer Design Pattern
Reference: COS240 Syllabus
Java Methods Stacks and Queues A & AB Object-Oriented Programming
Slides by Steve Armstrong LeTourneau University Longview, TX
Chapter 22 Object-Oriented Systems Analysis and Design and UML
ITEC324 Principle of CS III
ITEC324 Principle of CS III
Presentation transcript:

A Case Study in OO Design and Team Development The Game of SET: Maria Litvin Phillips Academy Andover, Massachusetts Advance Placement Program Professional Development , AP Computer Science A and Computer Science AB, Special Topic: Object-Oriented Design. Copyright © 2004 by College Board. Reproduced with permission. All rights reserved.

2 I thank Marsha Jean Falco, president of SET Enterprises, Inc. (and the inventor of the SET game) for the permission to use SET in this project. I am very grateful to Gary Litvin for his help with the program design and implementation of the GUI code.

3 The SET Game l SET is a simple card game which is gaining popularity. l has the official rules, examples, game variations, and other resources. l SET ® is a registered trademark of SET Enterprises, Inc.

4 The SET Game (cont’d) l A SET deck consists of 81 cards. A card has four attributes: –number of symbols (1, 2, or 3) –symbol shape (oval, squiggle, or diamond) –symbol fill (outlined, striped, or solid) –symbol color (red, green, or blue) l A “set” is three cards, such that for each attribute its values for the cards are either all the same or all different. One example of a “set”

5 The SET Game (cont’d) l At the start of the game, 12 cards are open and all the players look for a “set” in them. l The player who sees a set announces, “Set!” then promptly points to the three cards of the set. l If the cards indeed form a set, these cards are removed and replaced with three cards from the deck, and the player gets one point; otherwise, the cards remain on the table, and the player loses one point. l If all the players agree that the open cards don’t have any sets, 3 additional cards are opened.

6 Computer SET The deck The open cards A “Set” Computer speed control “Set!” button

7 Identifying Classes — CRC Cards l CRC (Class, Responsibilities, Collaborators) cards facilitate brainstorming for identifying classes in an OO project. l A CRC card is usually an index card that lists a class, its responsibilities, and helper classes. l CRC cards are informal; responsibilites are listed with few details (not a list of the class’s methods).

8 CRC Cards for SET ZetCard l Represents a SET card l Holds card attributes (color, fill, etc.) ZetDeck l Holds 81 SET cards l Shuffles and sorts the deck l Delivers cards one at a time ZetCard, ZetTable ZetTable l Holds the deck and the open cards l Opens and removes cards l Looks for a “set” ZetDeck, ZetAnalyzer Unfortunately, the name of the game, SET, clashes with java.util.Set and with names of setter methods. To avoid confusion, in this case study we use Zet in class and method names.

9 CRC Cards for SET (cont’d) ZetGameModel l Keeps track of the card table and the picked cards l Updates the display as necessary ZetTable, ZetTableDisplay ZetTableDisplay l Draws the open cards, picked cards, and the deck ZetTable, ZetGameModel ComputerZetPlayer l Displays computer’s control panel l Handles timer events l Keeps computer’s score ZetGame, ZetGameModel HumanZetPlayer l Displays guest’s control panel l Handles keyboard / mouse l Keeps guest’s score ZetGame, ZetGameModel ZetGame l Consolidates GUI l Creates and manages the players and the game model ZetGame, ZetGameModel ZetAnalyzer l Determines whether three cards form a “set” l Finds a “set” in a given array of cards ZetTable

10 UML Diagrams l UML (Unified Modeling Language) diagrams represent graphically relationships between classes. Class AClass B extends Class AInterface B implements Class A uses Class B Object of Class A has-a(n) Object of Class B Collection A holds Objects of Class B or 1 *

11 SET Classes ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card

12 OO Design Basics ZetTable l Holds the deck and the open cards l Opens and removes specified cards l Looks for a “set” in the open cards l Rearranges the open cards, filling gaps when necessary ZetDeck, ZetAnalyzer Make each class implement a limited set of responsibilities.

13 public class ComputerZetPlayer extends JPanel implements ZetPlayer,... { public ComputerZetPlayer (ZetGame game, ZetGameModel gameModel) {... } public void start ( ) {... } public void stop ( ) {... } public int getScore( ) {... } public void setScore(int score) {... }... private void declareZet ( ) {... } private int state; private int delay; private int score = 0;... } Encapsulate classes; make classes interact via well-defined public constructors and methods.

14 ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card Arrange classes in layers: classes in the top layers utilize simpler, more general classes from the bottom layers.

15 ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card Minimize coupling (interdependences between classes, subsystems).

16 Provide tests for individual classes and sybsystems, where possible. ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card TestZetAnalyzer TestZetTable TestZetDeck TestDeck

17 A framework for other SET-type games and activities Classes for any card game Create reusable classes or frameworks (extendable systems of classes) when appropriate. (But do not overgeneralize!) ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card

18 Model View1 View2 View3 Controller1 Controller2 Follow established design patterns, when applicable. Model-View-Controller (MVC), (a.k.a Observer) design pattern: Controller(s) trigger changes in the model The model notifies all the “views” (observers) that it has changed The views are updated

19 MVC in SET ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card interface java.util. Observer java.util. Observable Controllers View (Observer) Model (Observable)

20 Team Development Group 2 Group 1 ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer ZetTableDisplay ZetTableModel ZetTable ZetAnalyzer ZetDeck ZetCard Deck Card TestZetAnalyzerTestZetTable TestZetDeck TestDeck Group 4 Group 3

21 Team Development (cont’d) Card Deck TestDeck ZetCard ZetDeck TestZetDeck Group 1 (2-6 people) Project Leader ZetAnalyzer TestZetAnalyzer ZetTable TestZetTable Group 2 (2-4 people) ZetTableDisplay ZetGameModel Group 3 code supplied (or 2-3 people) ZetGame ZetMenu ZetPlayer ComputerZetPlayer HumanZetPlayer Group 4 code supplied

22 Developers — Group people l Classes: –Card –Deck –TestDeck –ZetCard –ZetDeck –TestZetDeck l Required skills: –Basic constructors and “get” methods –java.util.ArrayList –Selection Sort or Collections.sort(...) –Inheritance, super(...) ZetDeck ZetCard Deck Card TestZetDeck TestDeck

23 l Classes: –ZetTable –TestZetTable –ZetAnalyzer –TestZetAnalyzer l Required skills: –Array algorithms –Static methods –Modulo arithmetic Developers — Group people ZetTable ZetAnalyzer TestZetAnalyzerTestZetTable

24 l Classes: –ZetTableDisplay –ZetGameModel l Required skills: –Graphics –MVC concept and java.util.Observer / Observable Developers — Group 3 Code is Supplied (or 2-3 people) ZetTableDisplay ZetTableModel

25 l Classes: –ZetGame –ZetMenu –ZetPlayer –ComputerZetPlayer –HumanZetPlayer l Prerequisite skills: –GUI design –javax.swing –Mouse, keyboard, and timer event handling Developers — Group 4 Code is Supplied ZetGame ZetMenu interface ZetPlayer ComputerZetPlayer HumanZetPlayer

26 Group 1 Task 1 (1-3 people) Card Deck TestDeck Task 2 (1-3 people) ZetCard ZetDeck TestZetDeck

27 public class Card implements Comparable { public Card (int id) {... } public int getId ( ) {... } public boolean equals (Object other) {... } public int compareTo (Object other) {... } public String toString ( ) {... } // Fields: private int id; } Group 1 Task 1-a

28 public class Deck { public Deck ( ) {... } public Deck (int capacity) {... } // creates an empty deck // of given capacity public int getNumCards ( ) {... } public boolean isEmpty ( ) {... } public int add (Card card) {... } // adds card to the top public Card takeTop ( ) {... } // removes card from the top public void shuffle ( ); public void sort ( ); public String toString ( ) {... } // Fields:... } Group 1 Task 1-b See implementation tips in Deck.java

29 public class TestDeck Create an empty deck Add a few cards Print out Shuffle Print out Sort Print out Remove cards one by one; print out after each removed card Group 1 Task 1-c

30 public class ZetCard extends Card { // Combines the four attributes to make a // unique ID in the range from 0 to 80. public ZetCard (int number, int shape, int fill, int color) {... } public int getNumber ( ) {... } public int getShape ( ) {... } public int getFill ( ) {... } public int getColor ( ) {... } public String toString ( ) {... } // Fields:... } Group 1 Task 2-a

31 public class ZetDeck { public ZetDeck ( ) {... } // creates a full deck of // 81 SET cards } Group 1 Task 2-b public class TestZetDeck Create a ZetDeck Remove and print out three top cards Group 1 Task 2-c

32 Group 2 Task 1 (1-2 people) ZetAnalyzer TestZetAnalyzer Task 2 (1-2 people) ZetTable TestZetTable

33 public class ZetAnalyzer { public static boolean isZet (ZetCard card1, ZetCard card2, ZetCard card3) {... } public static int[ ] findZet (ZetCard[ ] cards) {... } } Group 2 Task 1-a See implementation tips in ZetAnalyzer.java

34 public class TestZetAnalyzer Create a ZetDeck Open and print out a few cards Find and print out all “sets” by calling isZet on all triplets of cards Find and print out one “set” by calling findZet Group 2 Task 1-b

35 public class ZetTable {... } Group 2 Task 2-a See the specs in the javadoc docs and the implementation tips in ZetTable.java

36 public class TestZetTable See javadoc documentation for ZetTable.java Create a ZetTable object Simulate a SET game for one player: - Call table.findZet ( ); while a “set” is not found, call table.open3Cards ( ); if it returns false, the game is over - Print out the “set” - Call table.remove3Cards (...) to remove the “set” - If not enough cards open ( ! table.enoughOpen( ) ), open 3 more cards; if can’t open, the game is over - Repeat the above steps until the deck is empty Group 2 Task 2-b

37 When everyone has finished... l The project leader collects the code from the groups. l The project leader adds the supplied classes: l The QA (Quality Assurance) team (everyone) tests the application. –ZetPlayer –ZetComputerPlayer –ZetHumanPlayer –ZetGame –ZetMenu –ZetGameModel –ZetTableDisplay

38 Summary l OOP helped us split the project into small classes with well-defined limited responsibilities. l Encapsulation helped us minimize documentation and interactions between developers.

39 Summary (cont’d) l Abstraction helped us make some of the classes (Card, Deck) reusable and to create a framework (ZetCard, ZetDeck, ZetAnalyzer, ZetTable) for other SET-type games and activities. l Inheritance helped us reuse the code from Deck in ZetDeck and made it easier to add different types of players.

40 l These slides and the Game of SET case study code are posted at: l See InstructorNotes.doc for suggestions on how to run this project with your students. l questions and comments about this project to: