3

I'm a little hesitant on what to name a view class.

I have a view class which I call ChooseImageView because that's what the user does in that view. After the user has chosen an image I display a view called ChosenImageView. Is it wrong to name classes after the user action instead of what the view class actually "is"?

1 Answer 1

2

Choosing a good name is important.

The name should:

  • Indicate the single responsibility of the class
  • Ensure that the data, methods, and implementation surprise no one
  • Indicate the level of abstraction that it is working at

If, in addition to all that, the name also:

  • Indicates what architectural level the object is at
  • Indicates what the user does with the object
  • Indicates a family of objects that the object belongs to

then it might be nice, but these can also cause problems.

Objects work best when they make as few assumptions as possible about the world around them. Get those assumptions wrong or let enough time go by that they become wrong and suddenly the name isn't helping, it's actually in the way.

A name should withstand changes to the world around it.

The problem with your question is you haven't described your class independently of the name you claim is problematic. So we don't have any better idea what it does then the problematic name gives us.

I'm guessing that an image is going to be chosen in some view. I can't think of a better name than that because that's all you gave me to think about. I end up thinking of things inspired by a thesaurus like, PictureSelectorGUI.

6
  • Thanks for your answer. Yes that's what the view does. Let's a user choose an image. But the class name ChooseImageView is very specific. Should you go for a more "generic" name? I guess when designing a framework/SDK you should aim for more generic names but when creating classes for an app it's more preferable to use specific (descriptive) names? Commented Jun 14, 2017 at 19:15
  • You're missing my point. I can't help you get away from this name or tell you if you should get away from or stick with it if you don't tell me what you've named. It's like you've asked, "Is Rex a good name for a ..." Where's the rest of the question??? Commented Jun 14, 2017 at 19:17
  • Sorry but I thought I described what the view does. It's a view where the user is presented three different options (buttons basically) so by pressing on any of them the user will choose an image. That's the purpose of the view. Commented Jun 14, 2017 at 19:24
  • 1
    @PeterWarbo It think that what CandiedOrange is trying to say is that the actual name is neither right nor wrong. In order to be able to say whether is right or wrong we need to know in which level of abstraction the classes live at. For that, we need to be more familiar with the design and the model. So far, ChooseImageView is a quite generic name that could involve a lot of things related to the UI from just screen layout till the implementation of a widget within a panel.
    – Laiv
    Commented Jun 14, 2017 at 20:30
  • 1
    @Laiv thank you. I'm trying to express confusion and it's coming out all confused. :) Commented Jun 14, 2017 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.