What do you call classes without methods?

What do you call classes without methods?

For example,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class A
{
public string something;
public int a;
}
</code>
<code>class A { public string something; public int a; } </code>
class A
{
  public string something;
  public int a;
}

Above is a class without any methods. Does this type of class have a special name?

4

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).

8

I’d call it struct or record because it is used for data storage and this is very common to languages like C as you can see there: struct (C programming language). So personally I would prefer use a struct instead of a class that is more suitable and readable:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>struct A
{
public string something;
public int a;
}
</code>
<code>struct A { public string something; public int a; } </code>
struct A
{
  public string something;
  public int a;
}

Usually they are used as DTOs (Data Transfer Object) as said the others.

1

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.

2

I would call such a class a mutable data holder, and have sometimes used a generic form:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class DataHolder<T>
{
public T dat;
}
</code>
<code>class DataHolder<T> { public T dat; } </code>
class DataHolder<T>
{
   public T dat;
}

Note that wrapping dat within a property will degrade performance and offer no benefit, since there’s nothing that a property accessor could do (other than read/write the field) which wouldn’t break some implementations. Further, it may be necessary to use Interlocked methods with dat (or, if it’s a struct, with fields thereof), but that wouldn’t be possible if dat were wrapped in a property.

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>myData = myCollection.GetData(myKey);
</code>
<code>myData = myCollection.GetData(myKey); </code>
myData = myCollection.GetData(myKey);

would have a clear meaning if GetData returned an immutable class type or a struct (“mutable” or not) which did not contain references to mutable data. If it returned a mutable class object, however, it would be unclear whether any changes to that object would consistently be ignored by the underlying collection, consistently result in clean updates to it, or cause some irksome or unpredictable behavior meeting neither description.

If one wished to have a collection return data in a mutable object, the correct paradigm would often be something like:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>var myData = new WhateverType();
myCollection.GetData(myKey, myData);
myData.ModifySomehow();
myCollection.StoreData(myKey, myData);
</code>
<code>var myData = new WhateverType(); myCollection.GetData(myKey, myData); myData.ModifySomehow(); myCollection.StoreData(myKey, myData); </code>
var myData = new WhateverType();
myCollection.GetData(myKey, myData);
myData.ModifySomehow();
myCollection.StoreData(myKey, myData);

Using that approach, there is a clear implication that GetData will cause myData to be populated with data from the collection, but myCollection would not be expected to keep a reference to it once the function was complete, nor would it use it for any other purpose. StoreData would likewise copy information myData to its own internal data structure without keeping a reference. Note that one advantage of this approach is that if the client code will be reading many data items within a loop, it may safely create one instance of myData outside the loop, and then reuse that same instance every time through. Likewise, myCollection may be able to reuse the object instance associated with the key (copying data from the passed-in instance) without having to create a new instance.

Depending on the context, I call them Entities. On my boring business applications, they usually map 1:1 to my DER.

I would call it a Schema.

This covers multiple uses such as representing a database table, or a deserialised record, or a DTO, etc

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật