Is it ever a good idea to use the design pattern name in the implementing classes? [closed]

Recently I came across a moderately large python codebase with lots of MyClassAbstractFactory, MyClassManager, MyClassProxy, MyClassAdapter etc. classes.

While on the one hand those names pointed me to research and learn the corresponding patterns, they were not very descriptive of what the class does.

Also, they seem to fall within the forbidden list of words in programming: variable, process_available_information, data, amount, compute: overly broad names, that don’t tell us anything about the function when used by themselves.

So should there be CommunicationManager or rather PortListener? Or maybe I do not understand the problem at all…?

4

  • AbstractFactory is indeed a poor choice for a name. There is no way to know what is created by this factory, and when you’ll look for an entity which creates Animals, you’ll never find the corresponding factory by name.

  • AnimalAbstractFactory is not a wise choice neither, since in most languages, it would be redundant with the abstract keyword in the signature.

    This being said, there are several good reasons, highlighted by the comments, to actually include Abstract in the name: not only there are several contexts where you don’t have the full signature, but just the name, but also, keeping AnimalFactory for an interface may be a wise choice (unless, unfortunately, the convention of the language/framework is to prefix interfaces with I).

  • AnimalCreationUtility would also be a bad choice: if it’s a factory, make things easier for people who will read code, and call it a factory.

  • abstract AnimalFactory is ok. It doesn’t have redundancy, and is clear that it is an abstract factory which delegates the creation of animals to its children.

So yes, including the name of the design pattern is a good idea, but it should be only a part of the name, and shouldn’t be redundant with the other parts of the signature.

7

The whole point of using pattern names in classes is to make it easy to understand what the class does. If you name the class AnimalFactory it’s obvious that the class creates Animal instances. If the name of your class includes a name of a pattern and it does not describe what it does you’ve either chosen a wrong pattern or implemented it incorrectly.

Depends on the specific example. The Builder pattern is almost always best served by naming your class *Builder, while a Singleton doesn’t usually need to be named as such.

If you don’t put the pattern name in your class name, and maybe even if you do, you should generally put a comment in the class which explains that it implements a specific pattern.

1

I think it can work really well. For example:

// Command for retrying card entry with CVN.
public class RetryCardEntryWithCVNCommand { ... }

// Query for getting expired accounts
public class GetExpiredAccountsQuery { ... }

// Decorator for logging exception. Implies that it's an additional 
//mechanism for logging exceptions.
public class LogExceptionToDbDecorator { ... }

// Factory for creating account filters
public class AccountFilterFactory { ... }

2

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

Is it ever a good idea to use the design pattern name in the implementing classes? [closed]

Recently I came across a moderately large python codebase with lots of MyClassAbstractFactory, MyClassManager, MyClassProxy, MyClassAdapter etc. classes.

While on the one hand those names pointed me to research and learn the corresponding patterns, they were not very descriptive of what the class does.

Also, they seem to fall within the forbidden list of words in programming: variable, process_available_information, data, amount, compute: overly broad names, that don’t tell us anything about the function when used by themselves.

So should there be CommunicationManager or rather PortListener? Or maybe I do not understand the problem at all…?

4

  • AbstractFactory is indeed a poor choice for a name. There is no way to know what is created by this factory, and when you’ll look for an entity which creates Animals, you’ll never find the corresponding factory by name.

  • AnimalAbstractFactory is not a wise choice neither, since in most languages, it would be redundant with the abstract keyword in the signature.

    This being said, there are several good reasons, highlighted by the comments, to actually include Abstract in the name: not only there are several contexts where you don’t have the full signature, but just the name, but also, keeping AnimalFactory for an interface may be a wise choice (unless, unfortunately, the convention of the language/framework is to prefix interfaces with I).

  • AnimalCreationUtility would also be a bad choice: if it’s a factory, make things easier for people who will read code, and call it a factory.

  • abstract AnimalFactory is ok. It doesn’t have redundancy, and is clear that it is an abstract factory which delegates the creation of animals to its children.

So yes, including the name of the design pattern is a good idea, but it should be only a part of the name, and shouldn’t be redundant with the other parts of the signature.

7

The whole point of using pattern names in classes is to make it easy to understand what the class does. If you name the class AnimalFactory it’s obvious that the class creates Animal instances. If the name of your class includes a name of a pattern and it does not describe what it does you’ve either chosen a wrong pattern or implemented it incorrectly.

Depends on the specific example. The Builder pattern is almost always best served by naming your class *Builder, while a Singleton doesn’t usually need to be named as such.

If you don’t put the pattern name in your class name, and maybe even if you do, you should generally put a comment in the class which explains that it implements a specific pattern.

1

I think it can work really well. For example:

// Command for retrying card entry with CVN.
public class RetryCardEntryWithCVNCommand { ... }

// Query for getting expired accounts
public class GetExpiredAccountsQuery { ... }

// Decorator for logging exception. Implies that it's an additional 
//mechanism for logging exceptions.
public class LogExceptionToDbDecorator { ... }

// Factory for creating account filters
public class AccountFilterFactory { ... }

2

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