-1

Imagine you have a user object that holds the following data: id, name, email, telephone, address, created date, last update date.
To create the user you only need a subset of these properties: name, email, telephone and address.
The number of properties can go out of hand and it is easier to group them in a dictionary or another object, but how would you name this?

new User(name, email, telephone, address) -> new User(____)

3
  • I really don't understand what you're asking here... You seem to already have names for each member variable. Are you talking about the constructor parameters (the subset of properties that are needed to instantiate the class)? Not sure what language you're using, but most allow you to have optional parameters that have default values. Is that what you're talking about? Not sure what you mean about properties getting out of hand or grouping them into a dicitonary either
    – Ryan
    Oct 20, 2017 at 15:31
  • 2
    You already named those variables in the first line of your question. Personally, when writing the constructor, I prefer to name the parameters inName, inEmail, inTelephone, inAddress, etc - that makes it a little clearer for anyone who reads the code later, and it's my naming convention for most parameter variables. Now if you want to know what to name your proposed dictionary, you could name it userInfo. Otherwise, sub-divide them into a few separate objects, such as PersonalInfo (with name, email, etc), JobInfo (with title, shift, department, etc), and whatever other categories. Oct 20, 2017 at 16:12
  • 1
    If would ever need to design such a class, I would call a dictionary for a user's properties most probably something like userProperties. But I am here with the top most answer from the link of the former comment - tons of parameters is a design smell.
    – Doc Brown
    Oct 20, 2017 at 18:43

1 Answer 1

1

Dependencies

What you need to construct an object is that objects dependencies. The user object depends on that data being available or it can't be initialized.

You can pass this data in primitives and strings, You can cram it in a collection like a dictionary or a parameter object. In every form this is still what the user object depends on to exist.

However, dependencies don't just include field data. They also include references to collaborators. If your user object was required to send a report of it's status to some "friends" object the user object would need a reference to the friends object. It would be yet another dependency.

It might not seem like it but that reference is also "data you need to create an object".

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