0

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 know 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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Nodir Nasirov
  • 1,488
  • 3
  • 26
  • 44
  • 1
    Naming ProductDao does not mean Database integration is required. It can integrate with any data source such as file, web service, etc. so ProductDao is OK. ProductBuilder is bad name. – LHA Sep 17 '19 at 16:30
  • You are right, so that interface should be named `ProductBuildable` or something? – Nodir Nasirov Sep 17 '19 at 16:31
  • 1
    `ProductDaoDbImplementation`? – Vüsal Sep 17 '19 at 16:31
  • 1
    @Vusal: He is asking for name of interface name. Not implementation name. For implementation, they can be DbProductDao, XmlFileProductDao, WSProductDao, etc. – LHA Sep 17 '19 at 16:33
  • @Loc, "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..." - am I reading something wrong? – Vüsal Sep 17 '19 at 16:34

2 Answers2

3

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.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
1

I dont know if I have sure about your doubt but, a DAO is a Data Access Object basically it isolates the application/business layer from the persistence layer.

If you want to create a builder interface, maybe interface something like ProductBuilder.java, and the implementation ProductBuilderImp.java.

Check this two links