Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. How to package the Factory into separate component assembly?

How to package the Factory into separate component assembly?

Scheduled Pinned Locked Moved Design and Architecture
databasexmlperformancetutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chesnokov Yuriy
    wrote on last edited by
    #1

    There is some Interface e.g. database and many implementation Imp1, Imp2, Imp3, ... e.g. sql database, xml database, in memory database. Then there is a Factory to create those implementations returned as Interface objects. How to assign them to different assemblies? Interface and implementations should be in different assemblies to allow shipping to some clients product with sql database implementation, otheres with xml database etc... But what assembly to put Factory? If it is put with Interface or any other separate assembly it will need to ship all the implementations assemblies with it. I do not want to vialote DIP to allocate implementations directly in the code.

    Чесноков

    D 1 Reply Last reply
    0
    • C Chesnokov Yuriy

      There is some Interface e.g. database and many implementation Imp1, Imp2, Imp3, ... e.g. sql database, xml database, in memory database. Then there is a Factory to create those implementations returned as Interface objects. How to assign them to different assemblies? Interface and implementations should be in different assemblies to allow shipping to some clients product with sql database implementation, otheres with xml database etc... But what assembly to put Factory? If it is put with Interface or any other separate assembly it will need to ship all the implementations assemblies with it. I do not want to vialote DIP to allocate implementations directly in the code.

      Чесноков

      D Offline
      D Offline
      dasblinkenlight
      wrote on last edited by
      #2

      Although it's not stated directly, I assume that your question is about .NET (the word 'assembly' points in this direction). We solved this problem by creating an extra level of methods around the instantiation points of implementation, like this:

      class DbFactory {
      public static InterfaceDb Make(string kind) {
      switch (kind) {
      case "xml": return MakeXmlDb();
      case "sql": return MakeSqlDb();
      }
      throw new ArgumentException("kind");
      }
      private static InterfaceDb MakeXmlDb() {
      return new XmlDb();
      }
      private static InterfaceDb MakeSqlDb() {
      return new SqlDb();
      }
      }

      This code does not throw an exception when the assembly with SqlDb is missing unless you call Make("sql"); calling Make("xml") runs fine as long as the assembly with the implementation is present. Note: this functionally equivalent code does not work the same way:

      class DbFactory {
      public static InterfaceDb Make(string kind) {
      switch (kind) {
      case "xml": return new XmlDb();
      case "sql": return new SqlDb();
      }
      throw new ArgumentException("kind");
      }
      }

      This code requires both assemblies to be present.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups