6

One of the most powerful design techniques is to pay attention to what you know when. Following this can help keep your design simple. You might be setting your dependencies in the wrong place. ArrayExporter.Export() depends on both string[] arrayData and string outputPath. But which do you know when? If you don't know outputPath until you know the rest: ...


4

This doesn't seem very object oriented to me So what? Just because you can write OO code, doesn't mean you should. Use the approach best suited to the task. Is it ok to have a static class holding queries that accept and output tables, and that holds no state? Absolutely. This is exactly what static classes are for … in languages that are completely ...


3

Is this a sane approach to this problem? It depends. For many situations, this is sufficient and perfectly ok. If you don't create a new type of exporter every two weeks, or don't want to provide an extensible black-box library for dealing with exporter classes, it is probably better to keep things simple and live with a little bit of "duct tape". It ...


3

Do you mean having a static factory method on the class itself? This is a pattern used in various places, usually combined with a private constructor so that the class can only be created via the factory method. A case I've often seen it used for is where a class can be created in different ways that are insufficiently explicit from constructor ...


3

If A provides a constructor that initializes List<String> then whatever calls that constructor gets to decide. B might do that and use ArrayList<String> or B might require that whatever implementation for it be passed in to its own constructor which would pass it on to A I'm a big fan of overridable default values. So I'd lean towards a design ...


2

Composition coupled with edtiro templates will give you the easiest code reuse possibilities. Each view model that needs this information needs a reference to the shared view model. public class AddEditOrderDetails { [Display(Name = "Unit Price")] [Required] public decimal UnitPrice { get; set; } [Display(Name = "Quantity")] [Required] ...


2

Breaking down the problem What you've done right is identified that all exporters work the same. As a basic example (which I will expand on), this means something along the lines of: IExporter exporter = GetWhateverExporterYouWant(); exporter.Export("C:\\output.txt"); But you've also noticed that the input value (or rather its type) changes based on the ...


1

I really don't see how simpler can it get than this: class StudentDAO { public Student createStudent(Student studentToCreate) { jdbcTemplate.update(INSERT_SQL, .....); auditService.Created(studenToCreate.AuditInfo()): } public Student deleteStudent(Student studentToDelete) { jdbcTemplate.update(DELETE_SQL, .....); ...


1

Related code should be vertically close. You have the situation where, depending on how you look at it, different classes are related in different ways. I think the driving force here is the model and so I would put views related to a specific model in their own files views/foo.py views/bar.py.


1

I would get rid of the IHandlerCreator all together, and add a CanHandle method to the IHandler interface. My reasoning is that the logic for handling and determining if you CanHandle are closely related, and likely to change at the same time. In your IHandlerFactory, keep an array of IHandler objects, which could be injected in the constructor of the ...


1

Your situation is actually language agnostic and I would consider it to be a bad design in any programming language. The problems with circular references generally include the chicken&egg problem, because when you want to instantiate an object you do not know which you should instantiate first. Should you instantiate an ocean? But then you have to also ...


1

The way I would typically go about this is to use an interface. I'm not familiar with TypeScript but it supports interfaces. It also seems duck typing might be an option but either way the result is the same. To resolve the circular dependency, I would remove the tight coupling from Boat to Ocean at the very least. For example you could create an ...


1

If we use your method, this is actually very easy to test. You have an interface that exports database and arrays. Now add a test export class that has a simple mocking implementation that implements the interface so you could use it for tests. Also, could you explain a little more why this makes it hard to test? Also, maybe the export interface is not a ...


Only top voted, non community-wiki answers of a minimum length are eligible