• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is using classes as datastructure good or using array ?  RSS feed

 
aman bisht
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have problem understanding the use of classes, where to use it.
I and my friend independently wrote code for solving Rubik's cube,
I used array to store the state of cube,
but my friend used classes to store state of cube,
He made a class Face and had attributes containing nine colors of a face,
then he made six objects which stores information about six faces of the Rubik's cube.
The we applied the algorithm.
What do you think which approach is good toward solving this problem,
using Arrays or using classes ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use a hybrid. Having a Face class allows you to be more expressive because it can have methods like isSideSameColor().

I'd use a 3x3 array as an instance variable in the Face class though. This makes it see if rows/columns are all the same color.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is never only one correct way to do this.

I once did a workshop on an evening where we were with about 20 programmers. Each of us had to implement a simple game, using whatever programming language and tools that we wanted. At the end of the workshop we compared each other's solutions. It was very interesting to see how different people modeled the game in totally different ways. Each solution had its own pros and cons - for example if you wanted to extend the game with additional rules that would be much easier to do with some designs than with others, but some other design that wasn't as flexible had much better performance.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!