1

Topic: Factory of objects with different designers

There is an interface and some derivative classes which implement method Validate. In a makeweight to it, exists  IPaymentProcessor,  applies all rules, i.e. creates object and  method Validate () at Rule1, Rule2, . The task: to implement IPaymentProcessor public interface IBusinessRule {bool Validate ();} class Rule1: IBusinessRule {public Rule1 (string name) {...} bool Validate () {...}} class Rule2: IBusinessRule {public Rule1 (int month, int year) {...} bool Validate () {...}} interface IPaymentProcessor {bool MakePayment (CreditCard card);} class MyPaymentProcess: IPaymentProcessor {public bool MakePayment (CreditCard card) {//Here an ambush. If we need to add/udbrat a rule, the designer  changes.,//That it is necessary to climb in this code. That is completely not correct. var rules = new List <IBusinessRule> () {new Rule1 (card. Name), new Rule2 (card. Month, card. Year)}; foreach (var r in rules) if (! r. Validate ()) {return false;} return true;}} a question: how to replace list creation on the fly, any factory or the container to reduce connectivity? It is desirable from ready decisions under.NET, it is even better through Ninject (so in requirements). Digging aside Ninject/DI, came across a problem: or it is not clear as a miscellaneous kol-in parameters in the designer, or it is not clear in by what principle to do ninjectKernel. Get, or in our case something like GetAll, for listing.

2

Re: Factory of objects with different designers

Hello, licedey, you wrote: L> the Question: how to replace list creation on the fly, any factory or the container to reduce connectivity? It is desirable from ready decisions under.NET, it is even better through Ninject (so in requirements). At you the list changes in a program operating time? If is not present simply suppose it in static variable. If it would be desirable  register all copies in the ioc-container and cause getall. If yes, as it is arranged ? Whether he can create a copy of a class with parameters? If at you specific rules depend on a context, that is use parameters accessible in specific request simply add level . Make a class-bilder which in the designer accepts fixed , and in a method build - context-sensitive. Also save the list .

3

Re: Factory of objects with different designers

Hello, gandjustas, you wrote: G> Hello, licedey, you wrote: L>> the Question: how to replace list creation on the fly, any factory or the container to reduce connectivity? It is desirable from ready decisions under.NET, it is even better through Ninject (so in requirements). G> At you the list changes in a program operating time? G> if is not present simply suppose it in static variable. If it would be desirable  register all copies in the ioc-container and cause getall. In static it does not turn out, because the heap of requests with different CreditCard comes, and already on the basis of this object and form . G> If yes as it is arranged ? Whether he can create a copy of a class with parameters? Emmas... And  here , it is the bizes-logician ASP.NET MVC applications. On Api  the data about CreditCard, and the task of class PaymentProcessor  its correctness and to return true/false G> If at you specific rules depend on a context, that is use parameters accessible in specific request simply add level . Make a class-bilder which in the designer accepts fixed , and in a method build - context-sensitive. Also save the list . About  I will think, while made so, but in the same Ninject or AutoFixter, it somehow all is more fashionable and on the basis of a reflection. While  the decision through delegates-creator'y who lie in the list, we on it transverse and  create everyone Instance. But till now it seems that a bicycle.

4

Re: Factory of objects with different designers

Hello, licedey, you wrote: L> the Question: how to replace list creation on the fly, any factory or the container to reduce connectivity? It is desirable from ready decisions under.NET, it is even better through Ninject (so in requirements). Under.NET I do not know, but here classics QMetaObject. We can receive it with the help const QMetaObject * QObject:: metaObject () const. In QMetaObject there is a method newInstance though it is not especially basic even if it would be necessary to create a factory method, especially considering that the majority of classes are inherited from QObject. QObject * newInstance (QGenericArgument val0 = QGenericArgument (0), QGenericArgument val1 = QGenericArgument (), QGenericArgument val2 = QGenericArgument (), QGenericArgument val3 = QGenericArgument (), QGenericArgument val4 = QGenericArgument (), QGenericArgument val5 = QGenericArgument (), QGenericArgument val6 = QGenericArgument (), QGenericArgument val7 = QGenericArgument (), QGenericArgument val8 = QGenericArgument (), QGenericArgument val9 = QGenericArgument ()) const two things Are important in my opinion: 1) the First it enumerators, that is renumerators. It is possible to receive dynamic a title of methods and as to cause them, or there to connect signals slots. And it is possible to work with properties and so on. Another matter does not need to be forgotten that all it is made on switch. 2) the Second this obtaining of the interface and accordingly polymorphism by means of the virtual methods. All it gives the chance to add new objects from the same plug-ins and to create a new functional connecting their any method. Well, and as to.NET on Qt I left not only because it  and a C ++ but also because Qt possessed the same possibilities, that is . If on Qt all tested it personally with plug-ins during those far times on.NET it somehow was not possible to me. It is possible to mold, of course, that type that is described in "object-oriented design Receptions. Designing patterns" Erih Gamma, Richard Helm, Ralf Johnson, John Vlissids. And it is possible to use and other architecture that to us and show various metaobjective systems.

5

Re: Factory of objects with different designers

Hello, licedey, you wrote: G>> If is not present simply suppose it in static variable. If it would be desirable  register all copies in the ioc-container and cause getall. L> In static it does not turn out, because the heap of requests with different CreditCard comes, and already on the basis of this object and form . 1. To divide the code on two parts: classes with logic of handling and selection of the necessary class. 2. To make convenient API for each of parts. 3. To hide for API implementation. Start two variants: or we add in the handler method CanProcess (), or the dial-up of conditions => the output agent "is storable in adjustments comparison". Further  on conditions. L> about  I will think, while made so, but in the same Ninject or AutoFixter, it somehow all is more fashionable and on the basis of a reflection. It is better to solve at first a problem, and then with a clear conscience to chase for . It is necessary to rewrite Less.

6

Re: Factory of objects with different designers

Hello, licedey, you wrote: you tell is better, why your abstract  accept any abstract name, month, year. If I correctly understood, they  a name of the owner of a card, or month year of the termination of action of a card. I.e. they work not with abstract "line", "date", and with quite themselves specific - dataful cards, and the logic of check knows that is the given cards, and not what abstract. Here also transfer there a card entirely. Then your question will be resolved by itself.

7

Re: Factory of objects with different designers

Hello, velkin, you wrote: V> Hello, licedey, you wrote: L>> the Question: how to replace list creation on the fly, any factory or the container to reduce connectivity? It is desirable from ready decisions under.NET, it is even better through Ninject (so in requirements). V> Under.NET I do not know, but here classics QMetaObject. We can receive it with the help const QMetaObject * QObject:: metaObject () const. In QMetaObject there is a method newInstance though it is not especially basic even if it would be necessary to create a factory method, especially considering that the majority of classes are inherited from QObject. V> V> QObject * newInstance (QGenericArgument val0 = QGenericArgument (0), QGenericArgument val1 = QGenericArgument (), QGenericArgument val2 = QGenericArgument (), QGenericArgument val3 = QGenericArgument (), QGenericArgument val4 = QGenericArgument (), QGenericArgument val5 = QGenericArgument (), QGenericArgument val6 = QGenericArgument (), QGenericArgument val7 = QGenericArgument (), QGenericArgument val8 = QGenericArgument (), QGenericArgument val9 = QGenericArgument ()) const to Admit did not understand as it the specified code on pluses works, but under the description is similar to a reflection in.NET. To potter with it only it would not be desirable, strongly bulky code turns out, with a heap of checks. Therefore trying to make the decision the most laconic while stopped on delegates who create entities with any , returning  successors IRule. And in the ideal world, it would be desirable something like://Here in this place, it would be desirable IRuleFactory to create on the fly. Becomes through a Ninject/DI-pattern public PaymentProcessor (IRuleFactory factory) {//And here that like such . But it it is necessary to write the bicycle. Basically it also wrote already. this. _ factory = factory. Build ().Add <Rule1> (c => c. CardName).Add <Rule2> (c => c. Month, c => c. Year);} public bool MakePayment (CreditCard c) {return _factory. GetAll (c).All (v = v. Validate ());}

8

Re: Factory of objects with different designers

Hello, antropolog, you wrote: A> Hello, licedey, you wrote: A> you tell is better, why your abstract  accept any abstract name, month, year. If I correctly understood, they  a name of the owner of a card, or month year of the termination of action of a card. I.e. they work not with abstract "line", "date", and with quite themselves specific - dataful cards, and the logic of check knows that is the given cards, and not what abstract. Here also transfer there a card entirely. Then your question will be resolved by itself. To me on StackOverflow already 10 persons told about it. But this test job (and not mine), on knowledge DI, OOP, SOLID, Units-testings. In application to it such classes fastened, i.e. the task decided, and from me - to show the requirement  with .

9

Re: Factory of objects with different designers

Hello, licedey, you wrote: L> To me on StackOverflow already 10 persons told about it. But this test job (and not mine), on knowledge DI, OOP, SOLID, Units-testings. L> in application to it such classes fastened, i.e. the task decided, and from me - to show the requirement  with . It is the new form of search of candidates: 1.  someone's  on a forum in profile section. 2. To ask criticism/help/etc. 3. Pleasant we take in hand. I guessed?

10

Re: Factory of objects with different designers

Hello, licedey, you wrote: L> To me on StackOverflow already 10 persons told about it. But this test job (and not mine), on knowledge DI, OOP, SOLID, Units-testings. L> in application to it such classes fastened, i.e. the task decided, and from me - to show the requirement  with . And, interviews, senseless and ruthless. Good luck!

11

Re: Factory of objects with different designers

Hello, StatujaLeha, you wrote: SL> Hello, licedey, you wrote: L>> To me on StackOverflow already 10 persons told about it. But this test job (and not mine), on knowledge DI, OOP, SOLID, Units-testings. L>> in application to it such classes fastened, i.e. the task decided, and from me - to show the requirement  with . SL> I guessed? No. It , I the executor.

12

Re: Factory of objects with different designers

Hello, Sinix, you wrote: S> Hello, licedey, you wrote: L>> To me on StackOverflow already 10 persons told about it. But this test job (and not mine), on knowledge DI, OOP, SOLID, Units-testings. L>> in application to it such classes fastened, i.e. the task decided, and from me - to show the requirement  with . S> And, interviews, senseless and ruthless. Good luck! Thanks I Will transfer to the Frenchman who should explain this code still.

13

Re: Factory of objects with different designers

Hello, licedey, you wrote: G>> At you the list changes in a program operating time? G>> if is not present simply suppose it in static variable. If it would be desirable  register all copies in the ioc-container and cause getall. L> In static it does not turn out, because the heap of requests with different CreditCard comes, and already on the basis of this object and form . Not so the interface at yours . On the interface "" is a wrapper over Boolean (to within the calculation moment). Naturally, with it to work very inconveniently. It is all it is perfectly treated by interface correction: public interface Validator <T> {public boolean validate (T item);} public final class CompositeValidator <T> implements Validator <T> {private List <Validator <T>> peers; CompositeValidator (List <Validator <T>> peers) {this.peers = peers;} @Override public boolean validate (T item) {for (Validator <T> peer: peers) if (! peer.validate (item)) return false; return true;}} public final class LegacyRule1Adapter implements Validator <CreditCard> {@Override public boolean validate (CreditCard item) {return new Rule1 (item. Name).validate ();}} public final class LegacyRule2Adapter implements Validator <CreditCard> {@Override public boolean validate (CreditCard item) {return new Rule2 (item. Month, item. Year).validate ();}} public final class MyPaymentProcessor {private final Validator <CreditCard> validator; MyPaymentProcessor (Validator <CreditCard> validator) {this.validator = validator;} @Override public boolean makePayment (CreditCard card) {if (! validator.validate (card)) return false; return true;} }//Somewhere in the app startup/config/injection code: final Validator <CreditCard> paymentCardValidator = new CompositeValidator <> (new LegacyRule1Adapter (), new LegacyRule2Adapter ()); final PaymentProcessor = new MyPaymentProcessor (paymentCardValidator); Legacy Adapter' in the elementary case to do for each rule. In more difficult it is possible to look on any reflection on the basis of a class implementing IBusinessRule (for example, accepting type of argument, the designer of a rule and names of fields for transmission to the designer). Still it is possible to hide the composite processor behind static factory. Still the composition can be developed (conditional validators, etc...), all depends on language (convenient support of lambdas (anonymous functions) is necessary). As a result - any superfluous abstraction layers like "factories returning factories returning factories".

14

Re: Factory of objects with different designers

15

Re: Factory of objects with different designers

16

Re: Factory of objects with different designers

17

Re: Factory of objects with different designers