New answers tagged

3

How to model classes that can be extendable? In the field of software development, extensibility specifically refers to inheritance, and inheritance is not the correct approach here. The above class object is used to do the required job. But this model class serves another purpose and that is to pass information which is not received as a part of JSON ...


-2

One alternative is to add behavior to objects. You said the object "serves another purpose" in addition to be used to communicate json messages. So add both "purposes" (i.e. behavior) explicitly into the object instead of trying to "annotate your way out" the problem. Add toApiMessage() and the other "purpose" as ...


0

In your app, there’s a button “send email” and another button “send SMS”. There must be a difference in the code implementing the actions of these buttons, right? So what’s the difference? Very nonabstract; One calls new EmailMessage() and the other call new SMSMessage(). More abstract: EmailMessageFactor->newMessage vs SMSMessageFCtory->newMessage. ...


0

It appears that abstract factory shouldn't accept parameters else that would mean the client does* know the details. I have been attempting the same for years but I'm finding its incorrect e.g. // EmailMsgFactory implements MsgFactory // SmtpMsgFactory implements MsgFactory // but here you would still need specific params e.g. email vs // vs ftp vs slack; ...


0

Frankly, I would not expose any kind of "database-layer" or "CRUD" logic. Requests coming from the outside world should reference only "outside-world things," and should never let anyone anywhere directly manipulate your database.


1

Recap from comment thread Just recapping what was established in the comment discussion, as it explains the decisions I will make in the answer. My comment Word definitions matter when discussing concepts by using those definitions. I suspect you are thinking of an exam as a scheduled batch of tests being taken, i.e. "Class 5 will be taking the math ...


0

Websockets could be used to prevent the timeout. Then you can even send updates during the work to the client, without the client have to constantly ask for changes.


0

By default NUnit creates a single instance for all of your test cases within the same test class. Since NUnit 3.13, this behavior can be modified to create a new instance per test case and/or test method. Creating a single instance per test case is really useful when running your tests on parallel within the same class, as it reduces the total duration of ...


3

For such long-running tasks, delegate them to a background task. Then you could have 2 API endpoints, one to start the long-running task and a second one to request its current status. For example, your DELETE /CleanUpInactiveUsers/{years} invocation could return a redirect status code, redirecting the front-end to /CleanUpInactiveUsers/{years}/result if the ...


2

I would not avoid it, I would put some distinction between the business and database logic. Simply, Save(Thingy); Save can come from IRepostory, IDatabase etc. The save handles mapping and persisting the "thingy" to the repository. Pretty easy to switch from one database to another without changing the business layer. The business layer doesn't ...


0

It's possible to run NUnit tests in parallel. Tests also use the same instance of a TestClass. This second statement can easily be proven by following tests: public class MyClass { private int classMember = 0; [Test] public void Test1() { classMember += 1; Assert.That(classMember == 1); } [Test] public void Test2(...


0

It's been forgotten in the mists of time, but the original basis for Uncle Bob's SRP was based on the 1994 work of David L Parnas. From page 24: We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others. IMO, this wording ...


1

As it can be noticed, the Exam class is quite complex. I wonder if using a fluent interface/ the builder pattern is appropriate here. I don't think the Exam class is very complex. So far Exam only has getter and setters, which might be indicative of a Anemic domain model (https://en.wikipedia.org/wiki/Anemic_domain_model) In stead of starting with the class ...


1

It sounds like the conversion from List<Questionnaire> to List<ExamSet> is extremely sensitive. In some situations, its logic could even be evidence in a legal dispute, e.g. if someone suffered financial loss due to the exam and wanted to subpoena the way the questions were chosen. It is its own "concern" (as in separation of concerns) ...


1

IoC in CliFx So it seems that the actual problem that you are trying to solve is the way CliFx locates commands via AddCommandsFromThisAssembly, which prevents normal IoC workflow because commands are (seemingly) instantiated outside of IoC. Well, the latter is not true, because CliFx supports IoC integration, so it can instantiate all the dependencies for ...


0

OK so, yes, you have several things here which don't fit the normal DI pattern CLI application - Runs once, does a thing and quits CliFx - designed for a CLI application with multiple "commands" essentially multiple apps put into one. Your multiple mini apps don't share their dependencies But none of these really change anything, you still have a ...


1

You’ve asked two questions here and I think things will make more sense with a deeper dive into API architecture. The first thing I will say is than an API should ALWAYS have an independent ViewModel as the request/response data objects. I’ll address that in more in question 2. ViewModel: A data model passed between an external entity and the presentation ...


6

All test frameworks I know create a new separate instance of the test class for every single test. Not just because of concurrency, but also to make sure every test starts with the same state instead of having the object in whatever state a previous test left it in. Concurrency problems typically arise from static fields or singletons of some sort.


5

This is not a correct way to think about performance. As a result, you'll make your code harder to follow and more error prone, while having no gains in performance. The correct way consists of profiling the piece of code to determine the exact location of the bottleneck. Profiling is an essential and mandatory step: you shouldn't try to guess where is the ...


0

There are two reasons that I store time as UTC. First, is that with global users of some of the applications I work on, local time varies per user, so local time for a user that entered the data may not be local time for a user viewing the data later. Second, timezones change. They are subject to the whims of governments. What is UTC +5 today could be UTC +6 ...


4

This is how I do it: public B(int v) : base(v) { // Empty } Motivation is that I want to be explicit on the fact that I intend this to be an empty code block. When I come back to this code some time in the future, I'd know that it is not that I forgot to write the code. Consider also to extend the comment with the an explanation ...


-2

If the class won't be used by third parties and you don't need an overloaded constructor, don't write an empty constructor. But... Imagine you already shipped the product, and third parties use your class. A few months later there's a new requirement that makes you add a constructor with an argument. Now, by doing so, the C# compiler no longer generates a ...


0

Focus on Responsibilities. A view model has a particular job. You've already resolved to depend on the model in order to do that job, but the details of the connection between the two only matter insofar as they support the view model's ability to do what it needs to do. In your specific examples, one is sensitive to changes in the model and one is not. Will ...


0

I recently realized that the new features of C#, especially version 9, allow new non-OOP ways of organizing code. As a result I produced the F package at https://github.com/kofifus/F which is still a work in progress but has been successfully used in medium sized projects. The general idea is to decouple the OOP concept of 'class' into separate State, Data ...


1

In my opinion, the Entity Framework Data Context class IS your Repository. And in fact, recently I'm moving away from EF all together. I build mostly web sites with an Angular front-end. And my WebAPIs are just a thin veneer over the datastore. They query my SQL databases using the new JSON support in SQL server. And directly ship that JSON to the client. No ...


1

Some well-known programs in similar genre often employ "modes": it ranges from generic layout presets to unique specialized views with familiar elements. You may design each module as a component, that can be embedded into a MDI window or a tab and linked to a shared controller. Allow the user to choose which modules they want to work with, or ...


3

Why not both? keep your system modular, with the option of executing / using each module on its own have an integrating GUI which allows to call the other modules, and maybe coordinate their interprocessing. There are several technical options how this can be achieved, depending on the communication requirements of the different modules. I cannot tell you ...


4

So now I'm confused as to where I should my validation logic because for a ValueObject I think it should be inside the value object somewhere. There are a few different things going on, which is a source of some of the confusion When you write code like public Age(int age) { if age < 0 throw new ArgumentException(age); Value = age } The guard ...


0

I prefer a static factory method for new object creation. In it's most basic form, that looks like this: public class Age { public int Value { get; private set; } private Age(int age) { Value = age } public static Age Of(int value) { // perform validation, throw exception if value doesn't meet the requirements ...


0

While building it yourself is certainly a good way to learn; building a project that you want is best. You learn along the way. However, in this case, the best way to learn about such a prolific topic is to stop reading sources that fawn about these things and start to learn about the flaws and criticisms. Great thinkers like Uncle Bob, have brought many ...


2

I've been shared between WPF, Qt, JavaFX years ago, and chose WPF/c#/XAML/MVVM and find it very fast to develop, excellent to maintain, powerful in terms of possibilities and performance; it relies on DirectX and is not crossplatform for this reason, but Avalonia is a cross-platform alternative to WPF. I also can inject easily in WPF apps: native c, c++, ...


Top 50 recent answers are included