Not that this will unconfuse you…, but I’ve wanted to share this somewhere, possibly for my own benefit…
I think that what’s going on is that SmartThings is using the Object-Oriented (OO) “Factory Pattern”. This is very common pattern, yet, my formal Java education is limited to one semester + a bunch of reading, so I’ve never studied, umm…, factories. Inaccurately, I’m assuming that when we add a Thing, the factory is used to create a Device Instance, and the factory performs important magic that links it to the correct SmartDevice Type.
Maybe @duncan or ? or @ben can someday give us a peek under the covers at the architecture? (And/or I’m getting in over-my-head at the moment, and need to study and better understand the possible OO patterns that could be in play here.). – Or this part of ST’s implementation may be proprietary.
creates objects without exposing the instantiation logic to the client.
refers to the newly created object through a common interface
The implementation is really simple
The client needs a product, but instead of creating it directly using the new operator, it asks the factory object for a new product, providing the information about the type of object it needs.
The factory instantiates a new concrete product and then returns to the client the newly created product(casted to abstract product class).
The client uses the products as abstract products without being aware about their concrete implementation.
really simple" eh? Well… perhaps after translating all the important terminology used in that snip!
…CP / Terry.