• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Orientation Logic  RSS feed

 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to find the Winner using Object Orientation logic I have my old logic from my Tic Tac Toe game but it is not Object Orientated. So I want to convert it and add that code to my GUI Tic Tac Toe. I need to return a winner or tie. Any pointers or ideas please feel free to add a comment.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use my Tic Tac Toe code I made for the console game but I want to implement that code to my GUI Tic Tac Toe Game. So I have been looking into researching how to do what I said and have not come up with the way I want to do it. I am planning to use Object Orientation as my title tells so I am going to go and research some more any tips or site with valid information would be a great help. Thanks for you help.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I'd forget about the code that has already been written and start from scratch. Analyse the problem from an OO perspective to identify the objects involved and hence the classes you need and the connections between those classes and only once you have the complete design should you think about writing any code.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd (kind of) echo what Tony says but I have found that you never really get to a "complete" design without doing coding. I subscribe to the idea that the code is the design (it's the detailed design) and that coding is largely a design activity. "Building" software is done by compilers and linkers (read the essays by Jack Reeves, second link returned by the Google search). Anyway, my spin to Tony's advice is that you should first come up with a general idea/vision of what you want to build, then go and tinker around with code, using it to test the validity of your ideas. Then refine and expand your ideas based on what you learn from tinkering with code by adding more code to tinker with.
 
Brian Bykenhaal
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have thought of as a outline for my code planning on thinking about it for a while to make sure I got everything and it works correctly.



1. Add a new method getOutcome it will return and Outcome enumeration.

2. To find winner or tie with winOrTie method using Player 1 X as cross or Player 2 as O nought

3. In the takeTurn method use the getOutcome to determine Whether the game is over or not.

4. In takeTurn have a display message to tell the winner or tie then game ends. The option is given to
clear board and start new match.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key to learning OOP is really understanding *why* and *how* it helps to program this way. Understand what the benefits are and how those benefits are gained. It also helps to have a good understanding of how things can be made more difficult if you do OOP poorly.

You have to go beyond the basic concepts of OOP like encapsulation, polymorphism, inheritance. Yes, it's important to understand them but also understand that there's more to OOP than these. These are just mechanisms that enable OOP. I think what gets lost on a lot of people (including myself) who are trying to learn OOP is that it's really just another way to organize your ideas. There are other ways to do that such as procedural and functional, for example. These are no less valid styles of programming than OOP. I would even argue that you can write a great program that employs a mix of these styles.

So don't get hung up too much on trying to make everything an object or method or whatever OOP thing. Try to see past the mechanics of encapsulation, polymorphism, and inheritance. Try to see what the benefits are to you, the programmer. Ask yourself things like this:

How does adding a getOutcome method make your code better?
Why would experienced people tell you that winOrTie has trouble written all over its name?
Why does calling getOutcome() from the takeTurn method sound like a BAD idea?
Why is it a BAD idea to have takeTurn method display a message to the user?

(These are not rhetorical questions, BTW. You need to ask them. Understanding the answers will get you closer to understanding how to think and program in an Object-Oriented way)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!