• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Trouble naming interface

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am making a specific single board game in Java. I would like to have an interface "Position" with methods contracted to describe the number of "men" on different squares on board, score etc. But if I call it "Position" I can not find a good name for the implementing classes ! I have read that I should not do "IPosition". Suggestions ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Boehm wrote: But if I call it "Position" I can not find a good name for the implementing classes ! I have read that I should not do "IPosition". Suggestions ?



hmm.. why ? suppose you named an interface as IPosition , then implementation class as Position ok. in future if you want one more implementation class then what you will name for that ?

see the java api , take an example of List . it is an interface , ArrayList,LinkedList, ... these are all implementation classes . but again that is you wish to name the interface as IPosition/Position . naming an interface with prefix *I* habit comes from c++
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael:

My personal preference is to avoid naming interfaces starting with 'I'. I'm kind of curious why you're creating an interface for position. Do you expect to have a need for more than one kind of implementation?

John.
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to be able to change implementation with minimal changes to classes and code using "Position"s. Say you were working with chess and wanted a Position interface, what would you call a first implementing class ?
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ChessPosition would probably be my first choice. I guess the difficulty I'm having is that position seems to be a very concrete concept, like a point or an integer, and I'm not seeing how you would implement it differently.

John.
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say you also want to develop som AI for playing your chosen game. Now you realise that your first chosen way to implement positions is not very efficient for doing eg. MinMax searching in your searchtree of positions being evaluated using some game-specific heuristic taking intu account the placement of the "men" ondifferent parts of the board. Now it would be nice to have all your developed algos for the search not getting into trouble because you change representation from something human-readable to a number of bitmaps ) Someone said: Always code to interfaces !
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, but the position (i.e., x,y coordinates, hex coordinates, etc.) really wouldn't need an interface. The movement would, and that's what I would write an interface for. You could then account for the different algorithms there. As for 'always' programming against interfaces, you probably should modify that to 'prefer' .

John.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently read some place that Sun suggests that you use adjectives for interfaces. For example, Positionable. I first found it a little weird but have come to like it because it frees you to name your classes and you want (Position) and you can easily recognize your interfaces.
 
Michael Boehm
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Revisting this I see I was not so clear. By Position i meant the whole position in the boardgame and not a "geometric" position eg. on a chessboard. So for instance with chess, a Position would hold info about what pieces where on which squares. I read some coding conventions for a larger project, think it was an open source project, and they suggested that a first class implementing the interface Interface should be named DefaultInterface. It works, but am not sure it is pretty
 
Sheriff
Posts: 28326
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Boehm wrote:By Position i meant the whole position in the boardgame and not a "geometric" position eg. on a chessboard. So for instance with chess, a Position would hold info about what pieces where on which squares.

I still don't see why you need an interface for this. However if you can imagine two different classes which would implement this requirement in two different ways, that might help you name the interface. But personally I can't imagine that, so I can't think of a name.

Or were you perhaps thinking of generalizing your Position entity to describe positions in games other than chess? Like Go, or bridge?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you're looking to use an interface "just because". I'm a huge, huge fan of interfaces, but they should be used when appropriate, and not otherwise.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic