Propper naming of builder classes in java

Nodir Nasirov :

I have a Product class, and Builder classes, one of them can build that product subclass getting data from database, another builder can build that product getting data from other sources. so far I have an interface:

public interface ProductDao {
  Product buildProduct(RetrieveBy by, String s);
}

an enum with building options:

public enum RetrieveBy {
  NAME, TYPE, BRAND
}

I do not now what is the best way to name class that is going to implement the interface and will build the product getting data from database, and other classes that can build that product getting data from other sources(JSON, XMLs, or property files) Someone suggested me to create just a single class and name it ProductBuilder, but, IMO this violates single responsibility principal.

GhostCat salutes Monica C. :

Thing is: there are no hard rules here, just conventions, and most importantly: that "precedent" that exists in your company/team/project.

In other words: do what everybody else does around you.

My personal style:

  • I would call the interface ProductBuiler ... DAO means "data access object", and that interface has nothing to do with that (directly)
  • I would then name the class ProductBuilderImpl for example. Or if you have one implementation per "source", then simply JsonProductBuilder or maybe ProductBuilderForJson.

But as said, the real answer is: there are no universal laws that dictate names. You should use what "feels" good for you and your team.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=311327&siteId=1