Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 17 Dec 2012 04:32:28 -0600 Date: Mon, 17 Dec 2012 10:32:26 +0000 From: lipska the kat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: proper use of .java files (layout) References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 89 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-B761MHkwpbHtn2EZFdYaZxSZVAxAtblZhlcc9ekTAgBXGdd1hA/YVQoM0OxHJ54dkY894YZQo4JVDFe!PEroeHsXDvHrWWzirxVabIrAwdVG2QG9uz+VVf1k9vM78uiNzOLcwTD+Mgi1YREcwvftR00sUiE= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3120 Xref: csiph.com comp.lang.java.programmer:20394 On 16/12/12 15:38, infinitum3d@hotmail.com wrote: > I'm trying to figure out the best way to layout a java program. Should I put each object into its own .java file? If I'm making a card game, that would be 52 .java files. Is that crazy? Normal? > > Or should I separate them by suit and just have 4 .java files? Or by value so there are 13 .java files? > > Thanks! > > I3D Here is a possible outline for a simple card game component It has NOT been compiled. Comments welcome Card.java public class Card{ //enumeration types for rank and suit perhaps ... } ========================== Deck.java public class Deck{ private Card[] deck = null; //implementation hidden from clients public Deck(Integer cardCount){ deck = new Card[cardCount]; //not all games use all the cards } ... } ========================= Dealer.java public class Dealer{ private Deck deck = null; public Dealer(Deck deck){ this.deck = deck; } public void shuffle(){ ... //delegate to deck ? } ... public List deal(Integer hands, Integer cardsPerHand){ ... } } =========================== Snap.java public class Snap { private Deck deck = null; private Dealer dealer = null; public Snap(){ this.deck = new Deck(54); // don't forget the jokers this.dealer = new Dealer(deck); } public void play(Integer numPlayers){ dealer.shuffle(); dealer.deal(numPlayers, 0); // 0 indicates deal all to players ... } ... } Java is well suited to an 'Object Oriented' approach to software design The above outline is just one of many possible OO solutions. Hope this helps lipska -- Lipska the KatŠ: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun