What do you call classes without methods?
For example,
class A
{
public string something;
public int a;
}
Above is a class without any methods. Does this type of class have a special name?
|
What do you call classes without methods? For example,
Above is a class without any methods. Does this type of class have a special name? |
|||||||||||||||
|
|
Most of the time: An anti pattern. Why? Because it faciliates procedural programming with "Operator" classes and data structures. You separate data and behaviour which isn't exactly good OOP. Often times: A DTO (Data Transfer Object) Read only datastructures meant to exchange data, derived from a business/domain object. Sometimes: Just data structure. Well sometimes, you just gotta have those structures to hold data that is just plain and simple and has no operations on it. But then I wouldn't use public fields but accessors (getters and setters). |
|||||||||||||||||
|
|
I'd call it
Usually they are used as DTOs (Data Transfer Object) as said the others. |
|||||
|
|
These are known as Plain Old __ Objects (PO_Os) where the blank is Java or C or CIL, or whatever language you're using. If they're being used as simple data blocks for communication, then they can be known as Data Transfer Objects (DTOs). If they're representing some externally provided data, they can be known as Entities. |
|||||||
|
|
I would call such a class a mutable data holder, and have sometimes used a generic form:
Note that wrapping Note that while mutable data holders may be useful for types (mutable or not) which need to hold data, they cannot safely be used for data interchange in the same way that immutable types would. For example, a statement like:
would have a clear meaning if If one wished to have a collection return data in a mutable object, the correct paradigm would often be something like:
Using that approach, there is a clear implication that |
||||
|
|
|
Depending on the context, I call them Entities. On my boring business applications, they usually map 1:1 to my DER. |
|||
|
|