Rob Sobers
Rob Sobers

Reputation: 21145

Is there a standard term for a class that contains just data, no logic?

I'm looking for a standard way to communicate to another programmer that a class is a essentially just a data container.

Take this simple User class for example:

class User
{
    public string userName { get; set; }
    public string passPhrase { get; set; }
    public Role role { get; set; }
}

"That component makes use of the User class, which is just a (insert here) class."

I want to say "data model", but I think that's too broad. Classes described as data models often have logic.

Upvotes: 4

Views: 824

Answers (11)

JasonTrue
JasonTrue

Reputation: 19634

Data Transfer Object may be correct, depending on the intent. It's essentially a container, but "container" is overloaded and generally refers to collection types.

Value Objects can have behavior, but if you have two independently created value objects with the same field values, and they can be treated as equivalent (e.g. the identity of the record doesn't matter), you could say that what you have is a value object. But usually Value Objects are best when immutable.

When there are a lot of Data Transfer Objects in a design, the design is sometimes pejoratively referred to as an Anemic Domain Model.

Upvotes: 1

Dexygen
Dexygen

Reputation: 12561

"Value object" is more precise in this case than is "Data Transfer Object". A value object contains just values; a Data Transfer Object additionally should implement a method for transferring that data to or from itself to or from some other entity. "Bean" is also an accepted term particularly within Java circles.

Upvotes: 2

MusiGenesis
MusiGenesis

Reputation: 75336

This isn't standard, but I often attach the "Info" suffix to a class name to indicate that the class is just meant to store and transfer information. So I would change your User class to UserInfo.

UserData would work, too, as would a "don't add any methods to this damn thing" comment at the top.

Upvotes: 1

Agha Ahsan
Agha Ahsan

Reputation:

Data Object, Data Transfer Object, DTO

Upvotes: 0

Mike Dunlavey
Mike Dunlavey

Reputation: 40679

How about: struct ?

Upvotes: 3

Reputation:

From A Gentle Introduction to Haskell

"A type like this is often called a tuple type, since it is essentially just a cartesian product of other types."

Upvotes: 0

Noah Campbell
Noah Campbell

Reputation: 1052

Data Transfer Object more commonly referred to as a DTO.

Upvotes: 1

Matt Wrock
Matt Wrock

Reputation: 6640

Sometimes these are called DTOs - Data Transfer Objects.

Upvotes: 9

JaredPar
JaredPar

Reputation: 755141

POD - Plain Old Data

Upvotes: 6

RMorrisey
RMorrisey

Reputation: 7739

In Java a class with only properties and getters/setters for each property is called a bean or POJO (Plain Old Java Object)

Upvotes: 1

Samuel Carrijo
Samuel Carrijo

Reputation: 17939

POXO - Plain Old X Object, where X is the language of your choice. Your case, seems like C#, so that's a POCO: Plain Old C# Object.

Upvotes: 1

Related Questions