factory-pattern

Using Ninject IOC to replace a factory

情到浓时终转凉″ 提交于 2020-01-13 07:42:06
问题 I've got a factory method inside a parser. Essentially as I load a token I look up the handler for that token, or drop through to the default handler. I've implemented this as a switch and as a Dictionary<string,Type> but both approaches require me to store the mapping somewhere else than the handler class. We are using Ninject for IOC and so I've realized I can also do it using kernel.Get<ITokenHandler>(tokenName); but that doesn't save me storing the information on what token the handler

Use of factory pattern

佐手、 提交于 2020-01-13 05:51:33
问题 Which way use of Factory is better(correct)? IPacket info = PacketFactory.CreatePacketObject(PacketType.Info, currentUser, DateTime.Now, " disconnected"); or should I throw out second method in PacketFactory and use this one? IPacket info = PacketFactory.CreatePacketObject(PacketType.Info); info.CreationTime = DateTime.Now; info.Creator = currentUser; info.Data = " disconnected"; or maybe some other? PacketFactory code: public static class PacketFactory { public static IPacket

Use of factory pattern

£可爱£侵袭症+ 提交于 2020-01-13 05:51:06
问题 Which way use of Factory is better(correct)? IPacket info = PacketFactory.CreatePacketObject(PacketType.Info, currentUser, DateTime.Now, " disconnected"); or should I throw out second method in PacketFactory and use this one? IPacket info = PacketFactory.CreatePacketObject(PacketType.Info); info.CreationTime = DateTime.Now; info.Creator = currentUser; info.Data = " disconnected"; or maybe some other? PacketFactory code: public static class PacketFactory { public static IPacket

Constructor Injection - Do we inject factories as well?

醉酒当歌 提交于 2020-01-12 07:16:27
问题 After listening to the Clean Code Talks, I came to understand that we should use factories to compose objects. So, for example, if a House has a Door and a Door has a DoorKnob , in HouseFactory we create a new DoorKnob and pass it to the constructor of Door , and then pass that new Door object to the constructor of House . But what about the class that uses the House (say the class name is ABC ) ? It will depend on the HouseFactory , right? So do we pass the HouseFactory in the constructor of

How to implement a generic RepositoryFactory?

为君一笑 提交于 2020-01-12 03:41:25
问题 I'm trying to implement a Generic Repository. This is what I've got so far ... public interface IRepositoryFactory { IRepository<T> RepositoryOf<T>() where T : class; } public class EntityFrameworkRepositoryFactory : IRepositoryFactory { private readonly IWindsorContainer _container; public EntityFrameworkRepositoryFactory(IWindsorContainer container) { _container = container; } public IRepository<T> RepositoryOf<T>() where T : class { var repository = _container.Resolve<IRepository<T>>();

Is this Factory Method creation pattern?

我的梦境 提交于 2020-01-09 12:18:27
问题 I have been using factory method creation pattern for awhile now. I was just recently told that this: public static class ScheduleTypeFactory { public static IScheduleItem GetScheduleItem(ScheduleTypeEnum scheduleType) { IScheduleItem scheduleItem = null; switch (scheduleType) { case ScheduleTypeEnum.CableOnDemandScheduleTypeID: { scheduleItem = new VODScheduleItem(); break; } case ScheduleTypeEnum.BroadbandScheduleTypeID: { scheduleItem = new VODScheduleItem(); break; } case ScheduleTypeEnum

Python - question about factory functions

此生再无相见时 提交于 2020-01-06 05:23:13
问题 I have a series of classes that I'll be registering as services to a higher level abstraction class. The high-level class will have a function that gets the lower level class based on init args, etc. Does this sound berserk? Also, what is this called? I call it factory function/class, but I really have no idea (which makes it harder to Google best practices). 回答1: It's called "metaclass programming". In recent versions of Python it's implemented by defining the __new__() static method and

how to implement factory design pattern in C#

[亡魂溺海] 提交于 2020-01-05 05:59:13
问题 I am trying to implement Factory pattern in my application. With reference to these links, I am trying to implement but stuck at one place & not sure how to proceed. How to update this class/method to improve Code Metrics http://www.dofactory.com/net/factory-method-design-pattern How to implement Factory pattern? Please find "// confused here how do I implement here" comment in my code to get where I am stuck. //DAL Layer public interface IReportHandler { IEnumerable<DocumentMapper>

How can I write this class to be fully generic and return different responses according to one request?

坚强是说给别人听的谎言 提交于 2020-01-04 04:54:10
问题 I was asked to create a series of reports for an application and as always, I'm looking for ways to reduce the amount of code written. I've started trying to come up with the easiest way to request a single report. Here's what I imagined: var response = ReportGenerator.Generate(Reports.Report1); //Reports would be an enum type with all of the available reports. As soon as I tried to design that, the problems appeared. Every report has a different input and output. The input being the entity

Abstract Factory with Unity

▼魔方 西西 提交于 2020-01-04 03:04:50
问题 I have a simple Abstract Factory implementation: public abstract class ICarFactory{ public abstract ISportsCar CreateSportCar(); public abstract IFamilyCar CreateFamilyCar(); } public abstract class ISportsCar { public abstract void Accelerate(); } public abstract class IFamilyCar { public abstract void Accelarete(); } public class BMWFactory : ICarFactory { public override ISportsCar CreateSportCar() { return new BMWi7(); } public override IFamilyCar CreateFamilyCar() { return new BMWM5(); }