Naming Classes Without a 'Manager' ================================== - [SomethingManager](#somethingmanager) - [Design Patterns](#design-patterns) - [Creational](https://refactoring.guru/design-patterns/creational-patterns) - [Factory Method](https://refactoring.guru/design-patterns/factory-method) - [Abstract Factory](https://refactoring.guru/design-patterns/abstract-factory) - [Builder](https://refactoring.guru/design-patterns/builder) - [Prototype](https://refactoring.guru/design-patterns/prototype) - [Structural](https://refactoring.guru/design-patterns/structural-patterns) - [Adapter](https://refactoring.guru/design-patterns/adapter) - [Bridge](https://refactoring.guru/design-patterns/bridge) - [Composite](https://refactoring.guru/design-patterns/composite) - [Decorator](https://refactoring.guru/design-patterns/decorator) - [Facade](https://refactoring.guru/design-patterns/facade) - [Flyweight](https://refactoring.guru/design-patterns/flyweight) - [Proxy](https://refactoring.guru/design-patterns/proxy) - [Behavioral](https://refactoring.guru/design-patterns/behavioral-patterns) - [Chain of Responsibility](https://refactoring.guru/design-patterns/chain-of-responsibility) - [Command](https://refactoring.guru/design-patterns/command) - [Iterator](https://refactoring.guru/design-patterns/iterator) - [Mediator](https://refactoring.guru/design-patterns/mediator) - [Memento](https://refactoring.guru/design-patterns/memento) - [Observer](https://refactoring.guru/design-patterns/observer) - [State](https://refactoring.guru/design-patterns/state) - [Strategy](https://refactoring.guru/design-patterns/strategy) - [Template Method](https://refactoring.guru/design-patterns/template-method) - [Visitor](https://refactoring.guru/design-patterns/visitor) - [Enterprise Integration Design Patterns](http://www.enterpriseintegrationpatterns.com/) - [Messaging Patterns Overview](http://www.enterpriseintegrationpatterns.com/patterns/messaging/) - [Classes names suggestions](#classes-names-suggestions) ### SomethingManager There's nothing more ambiguous than a `SomethingManager`. Avoid this word. Alan Green proposes a few alternatives in [his blog post](http://www.bright-green.com/blog/2003_02_25/naming_java_classes_without_a.html) that might be helpful in narrowing down what your class actually does. Giving your classes and objects good, descriptive names isn't easy. Steve McConnell provides a few helpful guidelines for routine naming in Code Complete: 1. **Describe everything the routine does** And we mean literally everything. If that makes the name ridiculously long, the name isn't the problem. Your routine is. 2. **Avoid meaningless, vague, or wishy-washy verbs** Like `UrlManager`, or `HandleOutput`, or `PerformServices`. Be specific. What does it do? If you can't answer that question succinctly, it may be time to refactor the code until you can. 3. **Don't differentiate routine names solely by number** I include this only for completeness. If you ever find yourself writing `OutputUser1` and `OutputUser2`, God help you. And God help the team you work with. 4. **Make names as long as necessary** According to McConnell, the optimum name length for a variable is 9 to 15 characters; routines tend to be more complex and therefore deserve longer names. Make your names as long as they need to be in order to make them understandable. 5. **For functions, try using a description of the return value** An easy, straightforward rule. Some examples are printer.IsReady(), pen.CurrentColor(), etcetera. 6. **Use opposites precisely** - for every `Open`, there should be anterprise Integration Design Patterns `Close` - for every `Insert`, a `Delete` - for every `Start`, a `Stop` 7. **Establish conventions for common operations** I'd say renaming classes and variables is one of my most frequent refactoring activities. [Creating good names is hard](https://martinfowler.com/bliki/TwoHardThings.html), but it *should* be hard, because a great name captures essential meaning in just one or two words. It's difficult to tell what something should be named until you're completely finished writing it. And like most code, it's never quite done, so the name may change over time. Succinct, descriptive variable, object, and function names can make the difference between wtf code and… well, code you'd actually want to work on. * *(see original resource: [I shall call it SomethingManager](https://blog.codinghorror.com/i-shall-call-it-somethingmanager/))* ### Design Patterns Design Patterns are typical solutions to commonly occurring problems in software design. They are blueprints, that can be taken and customized to solve a particular design problem in your code. * *(see original resource: [Design Patterns](https://refactoring.guru/design-patterns) or [wikipedia](https://en.wikipedia.org/wiki/Design_Patterns))* ### Classes names suggestions | Class suffix | Descripption | | :---------------------------------: | ------------ | | Storage | Stores something for future use. | | Repository | [Repository](https://martinfowler.com/eaaCatalog/repository.html) isolates domain objects from details of the database access code. The mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer.| | Mapper (DataMapper) | [Data Mapper](https://martinfowler.com/eaaCatalog/dataMapper.html) moves data between objects and a database while keeping them independent of each other and the mapper itself.| | Provider (DataProvider) | Provides a uniform interface between a service and a data source. Providers abstract physical storage, in much the same way that device drivers abstract physical hardware devices. | | Reader | Reads the data from the resources. | | Writer | Writes the data to the resources.| | Importer | | | Exporter | | ||| | Builder (Creator) |[Builder](https://refactoring.guru/design-patterns/builder) is a creational design pattern that lets you produce different types and representations of an object using the same building process. Builder allows constructing complex objects step by step. | | Fetcher | Retrieves data from the different resources like rss etc. | ||| | Splitter | Breaks out the composite data(message) into a series of individual data(messages), each containing data related to one item. See also Messaging Pattern: [Splitter](http://www.enterpriseintegrationpatterns.com/patterns/messaging/Sequencer.html).| | Agregator | Collects and store individual data(messages) into one composite data(message). The opposite to the Splitter. See also Messaging Pattern: [Agregator](http://www.enterpriseintegrationpatterns.com/patterns/messaging/Aggregator.html). | ||| | Serializer | Translates data structures or object state into a format that can be stored (for example, in a file or memory buffer) or transmitted (for example, across a network connection link) and reconstructed later (possibly in a different computer environment). See also: [Serialization](https://en.wikipedia.org/wiki/Serialization)| | Transformer (DataTransformer) | A transformer only changes one attribute, so that the result is the same basic type, but of a different capacity or intensity (voltage for example).| | Collector | [Collector](https://www.codeproject.com/Articles/1076386/Collector-Translator-And-Formatter-Pattern) is responsible for gathering the data.| | Adapter, Wrapper, or Translator | Converts the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces. The enterprise integration pattern equivalent is the translator.| | Formatter | [Formatter](https://www.codeproject.com/Articles/1076386/Collector-Translator-And-Formatter-Pattern) converts the data into a specific format based on the client needs. An example of a formatter would be converting the data to JSON or XML format. | ||| | Normalizer | Normalizes data from different resources to a common format. See also Messaging Pattern: [Normalizer](http://www.enterpriseintegrationpatterns.com/patterns/messaging/Normalizer.html).| | Converter | A converter makes the resulting object different in type from then initial condition, for example changing alternating current to direct current. | ||| | Handler (EventHandler, FormHandler) | The main role and intent of the Handler is to handle stuff: