views:

87

answers:

5

hi,

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

+2  A: 

I separate the data and operations into two separate classes.

Don’t. This flies in the face of object-oriented design.

Konrad Rudolph
I love OOD as much as the next guy, but in an N-Tier app, it is a good practice to have dumb entities (aka Data Transfer Objects) that are transferred over the wire from the Business tier to the Presentation tier.
Timores
@Timores well but even there the entity should take care of itself. This may often not be the case but I wouldn’t call it “good practice”. Separating the different tiers is conceptual, but the data tier doesn’t have to be a logic-less entity *in the code*. For a better example, look at Ruby on Rails’ ActiveRecord implementation (or generally MVC frameworks) where every entity takes care of itself although it’s just a “dumb” database column.
Konrad Rudolph
this is actually for an SOA design, data contracts and operation contracts need to be separated.but anyways, I am sure there are more valid reasons to break apart the data and logic. I am trying to see what the proper naming is so that we can avoid all kinds of variations.
cyberguest
@cyberguest: A lot of nonsense is advocated in the name of SOA. Separating data from logic is *not* strictly a requirement of SOA, nor is it good style. There are good reasons to separate *business logic* from *presentation logic* but there’s certainly no logic to break apart the inherent relationship between data and operations to be performed on it.
Konrad Rudolph
@Konard, I was using "Tier", meaning that a layer that is distributed on another machine. In such a case, loosely coupling is important. And there are frameworks which insist on "network transparency", so you have a nice object with lots of properties and methods, defined in the business tier, that is remoted to the pres layer, with some kind of transparent proxy. Then, the pres layer accesses this object, a lot, which causes lots of network calls and performance goes to /dev/null. If your program is on only one machine, go OOD the full way.
Timores
@Timores: yes I understood that but that doesn’t preclude combining data with its operations in the same entity.
Konrad Rudolph
@Konrad: OK, I'd be really interested to know more about the technology you use to be able to apply OOD in a N-tier app. Could you elaborate ?
Timores
@Timores: I’m unsure what you mean. What prevents you from using OOD in N-tier applications? In any case, you use serialization to send data (and possibly requests) over the network, e.g. by using SOAP. But ideally, this is just an implementation detail. For the most part you just use a (more or less) conventional object model and invoke methods on your data objects. I don’t see what prevents you from fitting your data objects with appropriate methods (intoorbit’s answer notwithstanding, which I think is excellent; but these are orthogonal concepts).
Konrad Rudolph
In particular, I don’t see what prevents DTOs from having behaviour. Obviously, you separate presentation logic from business logic but this isn’t particular to N-tier applications.
Konrad Rudolph
@Konrad: I've seen two "camps" of architects: one wants method-less DTOs , and one accepts methods with DTOs. I'd prefer to have methods in the DTOs (for the niceness of the OOD paradigm) but I think that doing this results in an object that mixes up presentation logic, business logic and DAL stuff, which creates its own share of problem.
Timores
+1  A: 

I usually go with Manager.

Timores
+1  A: 

Call it whatever you are comfortable with, just make sure you use that name consistently throughout your project. The closest thing we have is a Capability or a Receiver but even then these aren't quite what you're talking about.

However.

Do you have a specific reason for separating the data from the methods? Unless you talking about a class and its factory I'd be really surprised if this separation is truly warranted.

runrunraygun
from design perspective, this is kind of similar to the builder pattern.an analogy of this is building a car, the "car" runs through the assembly line, different machines build/add different parts to the "car". And the car might be further "modified" by the dealer, who knows nothing about the assembly line.specifically, this is for a WCF service, data contract and operation contract are separated.
cyberguest
+6  A: 

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.

I find this list really useful. I'd like to have its printed version somewhere inside one of the boxes of my table.
Roman
wow, thumbs and toes up
cyberguest
+1  A: 

Let's reason like following:

  • If the logic uses only one entity, move it to the entity itself (See rich domain model vs. anemic domain model).

  • So most of these classes are those which implement logic which deal with more than one entity, hence represent a collaboration.

Such class should not be named according to their responsibility. A technical term such as manager, controller, manipulator, etc. can still be use for naming convention, but the important part is first part of the name.

Example:

  • Entities: Product and Customer
  • Collaboration between the two: PurchaseService <-- what's important is Purchase, not Service
ewernli