Otros temas que te pueden interesar
|
||||
| Tema | Autor | Foro | Respuestas | Último post |
| [Duda] ¿Qué se hace en CLASS-OBJECT y FACTORY? | Kuk | Object-Oriented COBOL | 14 | 22 de febrero de 2017 15:49 |
![]() |
|
Administrador
![]()
|
Citación del post de Eslopes
Don't let this intimidate you. Abstract Factories are not only simple, but pretty flexible solutions that comes in handy very often. Once you master that concept you will not help yourself imagining new and creative uses for it. The checkout Checkouts usually comprises:
Our application should support many preconfigured checkouts, so we would be able to replace a checkout brand with another one without any impact in the business rules. The key here is to keep business logic as simples as possible and completely unaware of which device brand is being used, as long is provides the expected services. First let see what we are trying to avoid: Código COBOL:
The code above clearly shows the high dependency of classes that deal with checkout parts. If we add support to a different hardware supplier, our code would suffer with lots of "ifs" to check which equipament is in use. You could make your life easier by forcing those classes to implement a common interface, but still you would need to code a lot of methods to test the interaction between parts and class creation and all that code would go along business rules...creepy! These will be our checkout systems: Fujitsu . Cash drawer - model TeamPos1054258002 . Receipt printer - model TeamPoSFD21 HP . Cash drawer - model HPFK182AT . Receipt printer - model HPFK224AT In addition to get rid of high dependency (and the mess in the business logic) we would like also to define which set of parts our checkout is made of. We are going to use an XML file to define checkout configuration and which one our application is going to use. APP.config (xml file) Código XML:
The XML currently defines two suppliers: Fujitsu and HP. Each supplier could have multiple sets, but only one active. A global setting defines what would be the current supplier used by the app. The abstract factory The main interface of this design pattern is the abstract factory interface. This is the interface that will be used by the client app to create concrete factories. Lets call it ICheckoutAbstractFactory: Código COBOL:
NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro. ![]() ¿Te han ayudado? NO TE OLVIDES de darle a ![]() ¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick |
|||||||||
|
|
|
|
Administrador
![]()
|
The concrete factory
A concrete factory implements the abstract factory "create" methods. It will be the only point in the code that we need to update after add a new checkout system. This is a very specialized class which only responsibility is to create the proper parts. Our application has two concrete factories: FujitsuConcreteFactory and HPConcrete Factory. If you analyse the code carefully you maybe realize that we could implement only one factory ![]() Código COBOL:
The abstract product An abstract product is the interface that allow the concrete factory to load the proper product. Without that interface, the concrete factory would be useless (or much more complex than the necessary). Below the interface for Receipt Printers: Código COBOL:
The concrete product A concrete product in our checkout architecture take care of all communications with the hardware, so we are calling them drivers in this context. Here is the a concrete product for a Fujitsu Cash Drawer: Código COBOL:
Using our factory So, here is our abstract factory in action. You will notice that we are no longer directly instantiating the driver´s classes. Actually, that code has no idea which driver has been choosen. This has been delegated to the concrete factory. One very insteresting aspect is that our checkout parts can talk each other (for instance, when closing a sale, the receipt printer would open the cash drawer automatically). Código COBOL:
Abstract Factories are eveywhere ATMs, RTS games, DB connections, web frameworks and many more applications uses that useful pattern. Some examples: Spring.Net (Web Framework) .Net ADO.Net Microsoft COM (yes, even the COM implements that pattern) Download the source Cool things with OO Cobol - Source Code Some references in the web Abstract Factory .NET Design Pattern in C# and VB - dofactory.com Abstract factory pattern - Wikipedia NORMAS DEL FORO - para garantizar el buen funcionamiento del Foro. ![]() ¿Te han ayudado? NO TE OLVIDES de darle a ![]() ¿Quieres dirigirte a alguien en tu post? Notifícale haciendo clic en su Nick |
||||||||
|
|
|
![]() |
| Herramientas | |
|
|
| Archivo - Cobol Foro | Contactar con Nosotros - Cobol Foro | |||||||