-2

I have an object called LineItem, which can be added to an object called Quote. A Quote can have 0 or more of LineItem.

I have a service, which is a class, whose purpose is to add LineItem to the Quote. This class has a method called addLineItemToQuote. The method

  1. Reads the current number of lines from the Quote representation on database
  2. writes the counter+1 to the LineItem, which will be positioned last.
  3. writes quote_id into LineItem object to link it to the Quote
  4. sends INSERT command to the database with the LineItem information

I am having a hard time naming this service class.

I want to name it LineItemService but it does not deal strictly with the line item. It goes outside of the scope of the line item, since for example it counts the number of other line items on the quote.

I could call it QuoteService, but I already have another QuoteService that adds generic product line items (such as LineItem) and also specialty line items such as line items for packaging that are not considered to be a product.

What are some guidelines I can use to name this service so that it most closely reflects its purpose?

  • For now I called it AddLineItemToQuoteService – Dennis Nov 20 '18 at 22:35
0

Naming anything well is hard.

In this case does your code have to conform to any local name conventions you have?

If you have naming conventions, follow those conventions. You are stuck and the least you can do is not surprise your colleagues. They may grimace, but they won't be confused.

Otherwise, Green fields. I can suggest watching several of Kevlin Henney's presentations on YouTube, he has some points about naming. In general though brush up on your basic communication principles.

Specifically, the function/class is meant to encapsulate the implementation. So your description of exactly what is going on, should not be communicated in the name. Tomorrow I could replace the relational store with some other system of record, but still provide exactly the same service. So what is actually being done?

To put this in context. The service of having my haircut, is not called LowLevelScissorsHairManipulationService. It is called a Hair Dresser, or a Barber depending on the experience the customer receives.

So what is actually happening at that higher level of abstraction? What is the experience that the user of this service receiving? Up there its probably about (I am guessing here) some product. Specifically its about ordering a product?

Also if you are having conflicting names, is it the case that your new "service" is not in fact distinct? That it is in fact an operation offered by that other service?

  • thanks, well low level detail is adding a line item to the quote. Who does such an action usually? I am not sure. A customer requests an item, sales person adds the item via user-interface, and internally my code does the required checks and database access and insertion and update the screen to see the new quote with updated line items. I could naem that class SalesPerson, since a sales person would be th eone to add a line item to the quote. But that does not look right, since I would expect a SalesPerson class to be an entity object representing a person and not the quote operation – Dennis Nov 21 '18 at 19:40
  • You are focusing on the business implementation of the process. A Customer does not ask a Salesperson to add a line item to a quote. A Customer requests How much for 5 Product A, 2 Product B, and shipping that here? The fact that there is a SalesPerson, a quote order system etc is encapsulated by the business. Back to the point, your Salesperson is not adding a line item. They are manipulating a quote's quantity of a product. Whether something apparently looks like line items is an artifact of the visualisation. In this case the service is the Quote object, the manipulation is Add, or Update. – Kain0_0 Nov 22 '18 at 1:29
  • But again, context is key here how your architecture is arranged will require different names. For example if this Quote had to be manipulated by a Web Api, I would completely change the way you are handling this. The client would have a representation of Quote which it would manipulate internally, or if the client is too underpowered/code too sensitive call a Quotation Service to update a serialised quote representation (ie. a json model). On save/commit, pass the original + amended, or just new serialised quote through to the Quotation service, or a Deal service. It then perform checks/saves – Kain0_0 Nov 22 '18 at 1:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.