Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name of class that manipulates the entities

i have a general question regarding naming convention.

if I separate the data and operations into two separate classes. one has the data elements (entity), the other class manipulates the entity class. what do we usually call that class that manipulates the entity class?

(the entity I am referring to has nothing to do with any kind of entity framework)

manager? controller? operator? manipulator?

thanks in advance

like image 511
cyberguest Avatar asked Mar 12 '10 16:03

cyberguest


1 Answers

It depends on what kind of operations you're doing on those data contracts/entities. Here are some of my conventions. Let's use the example of a Fruit entity (and I'm not trying to imply these are all static methods, just pseudocode):

  • Repository: provides CRUD operations on a piece of fruit
    • FruitRepository.Save(Fruit item);
  • Manager: operations outside of simple CRUD.
    • InventoryManager.ShipFruit(Fruit[] items, string address);
  • Controller: reserved for use in the interface, as in Model-View-Controller. Makes interface or flow decisions how to display or operate on fruit.
    • FruitController.ShowDetails(string fruitId);
  • Processor: used on operations that are "batched" together. Often these are long-running or done offline.
    • FruitProcessor.RemoveSeeds(Fruit[] lotsOfFruit);
  • Manipulator: provides specific operations on a single entity or a collection of them.
    • FruitManipulator.PeelFruit(Fruit item);
  • Provider: provide more generalized or global operations.
    • FruitProvider.GetAllTypesOfFruit();
    • FruitProvider.IsInSeason(string fruitName);
  • Exporter: Convert some fruit into a format intended for file storage or perhaps transfer.
    • FruitExporter.Save(string spreadsheet);
  • Analyzer: Provides results about an individual piece of fruit or a quantity.
    • FruitAnalyzer.Weigh(Fruit[] items);
  • Service: exposes functionality in a loosely coupled or remotely accessible kind of way.
  • Assembler: Creates fruit by combining different data sources.
    • FruitAssembler.Combine(string speciesFile, string quantitiesFile);
  • Factory: responsible for creating/instantiating fruit.
    • FruitFactory.CreateApple(); // red delicious, McIntosh, etc
  • Builder: Provides a way to build up fruit by individual parts/properties.
    • FruitBuilder.AddSeeds(5); FruitBuilder.AddStem();

These are all somewhat loose. The main goal is to stay consistent within your own codebase and avoid conflicts with the technologies you're using-- ie. don't have a lot of Controller classes that aren't controllers if you're doing ASP.NET MVC.

like image 62
intoOrbit Avatar answered Oct 21 '22 01:10

intoOrbit