How to avoid general names for abstract classes?

In general it’s good to avoid words like “handle” or “process” as part of routine names and class names, unless you are dealing with (e.g.) file handles or (e.g.) unix processes. However abstract classes often don’t really know what they’re going to do with something besides, say, process it. In my current situation I have an “EmailProcessor” that logs into a user’s inbox and processes messages from it. It’s not really clear to me how to give this a more precise name, although I’ve noticed the following style matter arises:

  • better to treat derived classes as clients and named the base class by the part of the functionality it implements? Gives it more meaning but will violate is-a. E.g. EmailAcquirer would be a reasonable name since it’s acquiring for the derived class, but the derived class won’t be acquiring for anyone.
  • Or just really vague name since who knows what the derived classes will do. However “Processor” is still too general since it’s doing many relevant operations, like logging in and using IMAP.

Any way out of this dilemma?

Problem is more evident for abstract methods, in which you can’t really answer the question “what does this do?” because the answer is simply “whatever the client wants.”

6

The problem is not the name, but that you are putting too much in one class.

In your example class, some parts are very concrete (how the mails will be obtained). Other parts are very abstract (what you will do with the mails).

Better to do this with seperate classes, than with inheritance.

I suggest:

  • an abstract MessageIterator, subclassed by a POPMailBoxDownloader

  • another class that OWNS a POPMailBoxDownloader and does something with the messages.

1

If I cannot find a good name for a class I write an inline code documentation for the class. It describes the purpose of the class in one scentence. Usually I can derive a good name for the class from this description. This is also helpful for abstract classes.

If the description of class is “Logs into a user’s inbox and processes messages from it”, I would suggest “InboxProcessor” as a class name. If a derivative class has “Logs into a user’s inbox and moves spam email to a spam folder” as description, I would choose “InboxSpamMover” as a name.

I do not see a problem when using generic names like “processor” if it reflects the generic purpose of an abstract class.

If you have problems with describing the purpose of a class in one or two scentences, then you might have a design problem. Maybe the class is doing too much and violates the Single Responsibility Principle. This also applies to abstract classes.

0

To paraphrase Frank Zappa, it are what it is and should be named that way. Your example just doesn’t dig deep enough into what kind of processing is going on. Is it an EmailToTroubleTicketProcessor, an EmailGrammarCorrector or an EmailSpamDetector?

Problem is more evident for abstract methods, in which you can’t
really answer the question “what does this do?” because the answer is
simply “whatever the client wants.”

That’s not exactly true; the question you can’t answer for something abstract is “how does it do what it does?” because that’s implementation-specific. If an EmailSender class has a DeliveryStatus deliver(Email e) method, there’s an implied contract that an implementation will take an email, try to deliver it and return some status about how it went. You don’t care whether it connects to a SMTP server or prints it out to be strapped to a homing pigeon as long as the implementation does what was promised. Abstracts just quantify that promise so an implementation can say, “yeah, I do that.”

2

Think about why it’s bad to use such words. Are they descriptive? What words are there to describe the classes? EmailBaseClass? Could that be more descriptive than say EmailManager or something similar? The key is to have an insight about the class in question, so find proper verbs or nouns. Treat your code like it was poetry.

3

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