• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create a type for every reasonable domain concept?

 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I'm thinking about an advice for better application design I recently read in a few blogs or articles, which I'd like to share with you. Of course I'd be happy to hear your opinions and experiences on this topic. The idea is to create an extra type, i.e. a class, for everything in the code which represents a meaningful concept in the problem domain. For example the authors write that you shouldn't even use a plain String type but instead create a class which has a meaningful name in the domain even if it doesn't do much more than just encapsulate this String.

At first sight this seems to be a lot of work which doesn't add too much value to an application. This could mean to create a lot more classes which could possibly become confusing especially if you don't take care for reasonable naming conventions. Although I've not yet really thought about how much plain Strings I would have to replace because they are more meaningful for the domain than just a simple String.

On the other hand as I currently have to work with a typical legacy application. I can often see the benefit you would get from such a concept. In the said application almost everything is very generic and there are not very much custom types although the application is quite big. Basically everything is a String or even worse an Object. And maybe you have lists or maps to group some of these Strings and Objects. The rest of the application consists of relatively few but really huge "classes" (some are > 10.000 lines). As you might guess it's similar to large files of C code with just the file ending replaced with .java To make things even worse a lot of parameters, members, methods or variables are named very badly. In part because some pieces of code where duplicated or moved with simple copy & paste in the past without adjusting identifier names to fit the new context. Then it often happens that you just see 3, 4, 5 or 6 parameters of type String or Object and even the names of identifiers can't tell you what's really meant with a particular String or Object, i.e. what could be valid values for these parameters, variables or whatsoever. Of course there is no documentation or test which could clarify the meaning either.

Has anyone ever used the said concept in a real application? What are your thoughts about this idea? Is it worth the trouble? Maybe just to some degree?

Thanks in advance for your opinions!

Marco
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The idea is to create an extra type, i.e. a class, for everything in the code which represents a meaningful concept in the problem domain.



This might be one way to design a business/domain object model. However, typically healthy designs are driven and based on business/domain requirements. It is the logic and the difficulties of the requirements which indicate what should be an object (with behavior and data) and what should not be an object.

The classification as a "meaningful concept" alone is not sufficient to determine whether it should be an object. There are other factors.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK OK I see

Of course I agree that it's essential for good application design to create a model for all important parts of the problem domain as exactly as necessary.

But as you might have guessed I was more concerned about the types I described above which don't add much more value to a simple String than just giving it a new type-safe name. Of course I'm aware of the problem that there's almost no other way in Java to enforce such semantics within a String without creating a type for it. Even so I personally can see the benefit I've almost never stumbled across code which was written that way.

Marco

P.S. Sorry I didn't notice that you had added some more information to your post
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The classification as a "meaningful concept" alone is not sufficient to determine whether it should be an object. There are other factors.


Of course you're right! Maybe I wasn't precise enough as I'm not a native speaker. As I understand your hint you basically want to say that it not only depends on the problem domain but also on the requirements of the application in question. I didn't write it, but I should have mentioned that "meaningful" may vary depending on the requirements of the application. I hope this makes it clearer.

Marco
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it did.

Creating a new object type to simply hold a single String variable is a questionable design. This must be justified. Keep in mind that the number of objects in a single JRE instance require memory.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you're right. As so often when it comes to software design decisions "it depends" I just wanted to hear some other opinions.

After thinking about this some more time I decided to keep this concept in mind but only use it when I have the feeling that the meaning or semantic of simple primitive type (i.e. numbers, strings etc.) is not clear in a particular context and has to be enforced with an own type.

Anyway, thanks for sharing your thoughts!

Marco
 
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic