In practical terms it means using an custom (immutable) class over a string or some other primitive type.


  1. Publishing: International Standard Book Number.
  2. Finance: International Securities Identification Number.


  1. Can ensure the format of an identifier.
  2. Becomes a first-class member of the model.


  1. Adds persistence friction (e.g. Entity Framework).
  2. More code.
  • Should you use a custom class? Sure. Should you use them as IDs? Absolutely Not :) An ID with a business meaning would cause troubles along the way.
    – Songo
    Aug 21 '15 at 12:25
  • 2
    @Songo To me that's an argument that the IDs should have value semantics, but primitive types aren't the only types with value semantics, so that doesn't necessarily rule out classes imo. Feel free to post a competing answer though since I forgot to make that point.
    – Ixrec
    Aug 21 '15 at 12:29
  • 1
    An old question of mine touched on the subject with different opinions: programmers.stackexchange.com/questions/281827/… I went with creating the types and continue to do so.
    – Ziv
    Sep 1 '15 at 8:26

If you can give the class enough useful functionality to justify the added complexity of not being a string, then do it. For identifiers like ISBN and ISIN, I suspect this is not the case.

For an identifier class to be useful, I'd expect it to look something like this:

class ISIN {

If instead it looks more like this:

class ISIN {

Then I'd ditch the class entirely, use regular strings everywhere, and make sure I consistently use "isin" in all the relevant variable names.

Note that in some languages, adding a new type has almost no "added complexity" in typical programs, in which case you'd be encouraged to create the new type even if it had no functionality at all. But this is not the case for most traditional OOP languages like C++.


I would say go for it. I would argue that the advantages outweigh the disadvantages in this case. The extra code is likely to be pretty minimal and the persistence issue can be solved pretty easily be providing some sort of converter between your new Class and the type the database expects (I've never used Entity Framework but I know this is relatively painless in Hibernate).

One of the advantages you can get by defining your own class is that the compiler can ensure that any methods which want an ISBN or an ISIN will know at compile time if you try and pass in the wrong value. It will also be much harder to accidentally overwrite that field in your entity. We can avoid common errors like this entirely:


If ISBN is a class rather than a primitive type then the above code won't even compile, saving a lot of debugging time later.

  • 1
    setters and getters? Is it 1992?
    – Miles Rout
    Aug 26 '15 at 22:39
  • +1 go for it! disadvantages 15 minutes of typing; advantages: static type safety, c-tor parameter validation, future-proofing (convert-to methods).
    – Vorac
    Jul 17 '20 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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