instruction
stringlengths
34
36.1k
I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way". I have a few different types of windows, each type of which I have implemented as its own class. During run time, all of the currently open win...
abstract class BaseService { public void doSomething(); } class AService extends BaseService { public void doSomething(){ // Do something... } } class BService extends BaseService { public void doSomething(){ // Do something... } } class ServiceResolver { pubic static BaseService resolveService(St...
I need to access and process different resources from a REST API. For this I've come up with two different approaches: Approach 1: Create one class per resource, that handles accessing the data from the API. public class User { String name; public static User getUserFromApi() { //access API, set Attributes, pa...
I have a service class that performs some operations. One of the operations is a piece of code long enough to warrant extracting to a new class and unit test it in isolation: @Service public class ItemFinalizer { private final ItemPublisher itemPublisher; private final FollowupScanPublisher followupScanPublishe...
Backstory: I have subclasses that are supposed to override and define various functions, but not neccessarily all of them. They can't remain purely virtual though for obvious reasons, and so I am going to throw an exception instead. I just have to name the exception's class, and so it makes sense to use a term that imp...
I know, this question was asked in a slightly different way. But I didn't find it helpful. Sorry, long text. I'm new in a company and my work concerns graphics and numerical computation. My supervisor, who trains me and decides about my work being accepted or not, has a very specific understanding of "behaviour" with r...
I have a Vue/Quasar application that allows the end user to convert an Excel Spreadsheet into an Array and load it into a DataGrid. The Spreadsheet has a list of peoples names, email address, department and other profile data. The Spreadsheet could be 1000 names deep or more. FYI- I'm using AXIOS in the Vue applicat...
Suppose a customer needs to approach a staff member to register her. To model this, I have drawn the image below. However, I am not sure if what I have drawn, actually means both of them can register customer, not that a customer must first approach the staff. Could you let me know? Thanks PS. The customer will provide...
In a use case diagram, use case A "uses" use case B. I need to write the scenario based on steps of use case A. Since A "uses" B, I just wanted to confirm that I need to include the steps of B inside A as well. Depending on what B exactly does, steps of B may be incorporated in steps of A in any order. Am I right?
interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; SomeInput someInput = ...; SomeOutput someOutput = resolvers .stream() .filter(res -> res.canResolve(someInput)...
In a use-case diagram, use cases (bubbles) provide a functionality to an actor. For example, ecommerce site, actor "shopper" could use bubble "browse catalog" or "make payment". In this case, should a bank in an ecommerce example like above be considered an actor? I think not, since the bubble "make payment" does not p...
When I code in plain C there is quite a beautiful interaction between headers and c files in terms of documenting the code. I tend to add the documentation on the cc files (and yes I am aware that most people prefare them in the headers), but by doing this my header is now a birds eye view of the cc file. I can, at a g...
When we have bug/hotfix for the release candidate, we branch off of the RC branch and merge that fix back into the RC branch. We also merge (git merge, not cherry-pick) that fix into the master branch (red arrow): Is this any better than simply using trunk-based development? (Better meaning less merge conflicts, less ...
I'd like to state first that I'm still learning about scrum, so my apologies if my question seemed naïve. Lets say we have an E-learning portal, and I have the following user story: "As a University student, I want to see my fee for the semester, so that I know the remaining balance." I've written the following AC: Wh...
How would you go about making sure that "events" sent as messages to any sort of broker (Kafka, RabbitMQ etc) from multiple instances of the same service (load balanced) are actually added to the "queue(s)" in a correct order? So for instance.. Say we have a created an application/service. The service publish the follo...
Simple example (PSEUDO CODE): for (int i = 0; i < 100; i++) { START TRANSACTION; SELECT id, name FROM employees WHERE id = i; IF (someFunction(id)) { ROLLBACK; CONTINUE; // GO TO NEXT EXECUTION OF FOR LOOP } UPDATE company SET good = good + 1; COMMIT; } Can I use in this...
Suppose my system has Organizations which contain Departments which contain Work Areas, so it makes sense for me to query something like get /organization/o1/department/d2/workarea/w3/employees to get a list of employees in Work Area W3 that's part of Department D2 that's part of Organization O1. Let's further suppose ...
I made a state diagram for the Purchase object (parent) and for the Item object (child), as you can see below. One of my doubts is how to represent the integration between parent/child objects in the state diagram. The system flow is the following: Purchase object has an ArrayList to keep Item objects. Purchase is crea...
I've read a few articles which cover the set up for refresh tokens and JWT tokens Is there a best practice in how/when to get the next JWT token. In my head, there are a few different approaches. I will ignore authorisation for this post. Log in and authenticate On each server request, pull back a new JWT and refresh ...
I have 2 aggregates: Occupation and WorkActivity. An Occupation can have multiple WorkActivity. A WorkActivity can also belong to many Occupation. The aggregate is a basic element of transfer of data storage, according to Martin Fowler. So the WorkActivity can't be a value object of the Occupation because when updating...
I'm working in a situation where I have 2 different projects (kind of microservices, but they are still messed up in terms of the tables that each project can access - same domain). But so far, they are accessing (via Azure Functions) what is related to their domains in terms of database perspective (e.g Car domain acc...
I have seen multiple videos on microservices from guys building netflix/instagram and so on, and many and data consistency between microservices, but one thing that I can't really grasp yet, is as simple as responding back to frontend. Let's say we have frontend SPA or it could be anything else. The frontend has 2 appr...
I'm struggling to test functionality in a class where the class has to be in a certain state for the functionality to work, but the class cannot be put directly into a given state by design, to maintain state integrity. I'm developing the back end of a board game in Kotlin. It includes a Game class that is responsible ...
Let's say I have a collection of cars, all identified by VIN, such that cars/xyz123 will return the car with that VIN. Furthermore, I can get subsystems (children) by using URIs similar to cars/xyz123/drivetrain and cars/xyz123/chassis. Given a situation where I have a car without a VIN but with a distinct nickname, wh...
I am developing a website and I would like to allow users to use XMPP for live chat. I would like users to have the option use an existing XMPP account if they wish and store their XMPP username and password with their other account details. Obviously, there's a big issue with just storing passwords as plain text. Is t...
According to the 12-factor-app dev/prod parity principle, the developers' local environments and production should be similar. For developers working on a system with a complex microservice-based architecture, my understanding is that, this would mean that they need to build and deploy dozens of components to their loc...
I'm designing a web-app that will use a REST API. What I've never understood is what is REST's equivalent of HTML forms? HTML5 forms have a reasonably rich set of server-provided, declarative controls, constraints and validation. Is the server supposed to send a MIME type (name) or is there an equivalent of HTML forms ...
Sometimes in apps I look into the Resources and find files for, for example, a 256x256 version, a 128x128 version, a 64x64 version, AND a 32x32 version, of the same icon. When I see simple geometric icons like circles I already wonder why they do not just use SVG, but on top of that, what is the purpose of storing an o...
In C#, we have delegates, which are essentially variables (holders) for methods that follow a signature. So, I could write delegate void MyDelegate(int num); MyDelegate myMethodHolder; Now, what's always perplexed me about this is the reason for the first line. The language designers decided upon a syntax li...
Situation At the project I'm currently working on we're using Chakra UI to create our UI. But I guess this question applies to whatever (UI) library you're using. There are certain components that need to be customized and so we're creating our own components where we wrap the chakra ui component. Also, some components...
I'm the developer and maintainer of a FOSS C++ library, call it libfoo. There used to be just one variant of it; and I've made several numbered releases. Last year, I've created a second variant of libfoo (call it var2). The thing is, despite the new variant covering all functionality of var1, it uses a different appro...
Given we have several data transformation applications, which e.g. load an image, do some calculation and save some output. They make use of several internal libraries (internal = developed at our company and not published at pypi). When running these applications, shall we fix the versions of these internal libraries ...
In python I often see functions with a lot of arguments. For example: def translate(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p): // some code return(x, y, z) I like this pattern in some cases. I think it makes a ton of sense in library type situations where the variables are optional keyword arguments (e.g...
I'm trying to integrate a Camera to a more complex system in C++. The camera I'm using has a low-level API so I'm thinking about using a more simple interface. Basically what I'm planning to do is (in C++) : Camera will most probably run on a specified thread. Create an abstract Camera class interface with all my nee...
Consider the following scenario in an object-oriented environment. Sample code is in C++, but it could be any OO language. A software must control an external device, say a TV. From the start you know the software will need to handle different kind of TVs, so you go for an interface (pure abstract) to define the struct...
We are discussing the adoption of hexagonal architecture (ports and adapters architecture) in our team. Sometimes I use the rate of adoption as one rough metric about how beneficial a certain practice is. However, I can't find any hints about how widespread the use of hexagonal architecture is. Do you have any hints ab...
I am trying to understand the relationship between actors and their representation in the system. Please see the below figure In the figure on left, I have an abstract representation of my system. In the figure on left, I have a more detailed representation, such that the class Guest is supposed to represent the actor...
While testing my iOS application against the latest version, I've discovered a bug. For the purpose of this question, I am omitting the details of the bug. I was planning to migrate the application to React Native for cross-platform compatibility, even IF this bug didn't exist. Now that I've discovered the bug, however...
I'm designing a class that takes: 1 - An initial set of items (a simple collection/list) 2 - 1 or more Filter objects, that take the initial set of items and return a new set. Each Filter object may return a different set of items, so the main class performs and intersection of the result of these sets. Some of these F...
I want to use DynamoDB to save application operation data at the end of a session for auditing purposes without affecting the actual application latency. Because this date is only for auditing so we don't want to impact our prod latencies. I have few questions for implementing this: Should I decouple the DB write acti...
A customer of ours has a rather large (500+ LOC) service as central part of the project. Written in C# and consisting of rather clunky large imperative style functions, I was asked to improve the test coverage. After trying for some time to do so without touching the underlying code, I quickly found, that the result wo...
Not many architectures have skip instructions today. They are (usually) conditional instructions that skip the following instruction. A few architectures having these: PIC14, with its btfss and btfsc instructions Most PDP's from DEC (perhaps most famously the PDP-10) Data General NOVA I'm writing a superoptimizer (ju...
I have been asked to create a Django/Python web app that creates web-based, .pdf and excel reports from a Sage Evolution database. While the sage front-end is still being used. My client essentially wants to create their own "Sage" by only adding the features they need in a web app and hence making the process easier t...
I have 1 api key that has a rate limit 1000req/1min. I would like to somehow use 50% of that limit in service 1 and 50% of that limit in service 2. Let's say they're just 2 separate processes using the same api key. How could I implement distributed rate limiter like that? https://www.jeremydaly.com/throttling-third-p...
One of my web services hits a few hundred thousand visits per day where most of the operations are CRUD and we are thinking to get a cache sitting in front of our SQL database. I have had implemented cache before in some other projects using Redis. Basically, before I touch the database, I see if there's a cached versi...
When coding resharper recommends that if you're to discard or ignore the return of a method, that you use this syntax: _ = TheMethodICouldCareLessAboutTheReturnValue(); I know you could just call it without assignment to _ just the same, so why does the _ as an assignment matter?
Hey Software Engineers Currently we basically have a what I would call "modular monolith". A diagram would likely look something like this: What we want to do in the future is being able to deploy each module independently and move to a microservice environment where every module has its own database. We have a table ...
As the title implies, I would like to know if it is possible to create RESTful web APIs using MVVM architecture? Or we can use just MVC pattern to create web APIs?
When using SCRUM as an agile method for development, the first sprint (at least) will involve planning and requirements gathering, alongside user interactions. When I search sprint backlogs, it usually contains items from the product backlog, such as: Build a login system, Build the home interface, Design a database s...
I have a collection of classes in a SQL database that all share the same structure, and cannot be changed. They are similar to the example below. I am using Entity Framework Core and would like to have one set of code which can handle the crud for each of these tables. I've tried to generically the dto object back to ...
Suppose I have a static JS single-page-app that I want to deploy to production, and there are 4 production servers. I can deploy it to servers 1 & 2, try to test it, and then deploy to servers 3 & 4. I can deploy it to all four servers at once. Which one is more preferable and more common practice? (1) requires stick...
I have seen download managers manage to resume HTTP downloads from where they stopped. How are they able to resume downloads? Is it related to the Accept-Range Header? Or are there other mechanisms that download managers use to identify how much of the file has been downloaded and how much is left to be downloaded?
I looking for the scientific agreed upon definition of 'service' in Microservice/Service-oriented architecture. I found a the definition It logically represents a repeatable business activity with a specified outcome. It is self-contained. It is a black box for its consumers, meaning the consumer does not have t...
Usually, the web server that is serving a page includes the CSRF token inside the HTML. However when I'm using a cross-origin REST API, there is no "initial" page that could include the CSRF token. My idea is to respond with a CSRF token after the user logs in, but I'm not entirely sure if this protects against a CSRF-...
I would like to make an order-system with QR-Codes which is online. How I imagine it to work: A customer visits a restaurant. There is a QR-Code on his table which takes him to a public webpage where he can order the stuff he wants. So my question is: How can I check if the person ordering, is actually sitting in the r...
Vulkan introduces a member .pNext of type void* in all its core structs allowing to create handles. This member purpose is to allow to extend the structure by passing a pointer another one. This is mainly used for extensions, so that the same struct can be extended by two different extensions without any need to modify...
I'm working on moving some of our flags to a 3rd party system but I kinda have a hard time, determining what should be a feature flag and what should remain as authorization permission to a particular user. So wanted to ask, intentionally with less context on the type of flags I'm dealing with since it varies for each ...
I have a grid-based puzzle game, that is based on states. I need an algorithm that can find a solution for each game level. A game level starts in a specific state and ends in a unique, well-known state, so I need to find a path to walk from the start state to the end state. Each object in the game grid can be moved in...
So, a situation's come up at work today while refactoring my codebase. I have two classes that each derive from the same base class. The only significant difference between them is what they do at the beginning - one plays an array of audio files, while another plays just a single file. Each has a different set of audi...
Consider a scenario (in .Net Core world), where a microservice A collects data from external sources and sends this data asynchronously (RabbitMQ) to microservice B (the reporting system) where this data is finally stored and analyzed etc. As A has to reject invalid data from the sources, it therefore must first valida...
My software provides two functional requirements, and I represent them as Do A and Do B in the figure 1 below. At the same time, my software has a non-functional requirement to provide the interface in multiple languages. To the best of my knowledge, non-functional requirements should not be modeled as use cases, howev...
I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass method references to the two objects so that they can communicate with one another without needing to have an explicit ...
In Python projects, if your project spans multiple Python modules and you need to pass some data between the modules, as far as I know, there's 2 main ways: Pass the data as function arguments Create a module that stores all your global variables, and import the module from the modules that need to use it When does i...
Module A contains a gap buffer for manipulating text and some associated methods. Relevant to this question is the dependency on a Module B, used for syntax highlighting of text. Module A also provides a type that wraps its gap buffer with more stuff, and brings in some convenience methods for dealing with syntax highl...
I'm doing alone session with Event Storming for my application that I plan to build with DDD approach later on. Event Storming session is for learning purposes. My application domain logic is rather simple one. The application is called - "Vehicle Maintenance Management System" (VMM System). Below there are some genera...
I made a simple 2-window UI to practice the Observer pattern (which I hopefully managed to implement correctly): a window with some text fields meant for adding a new book to a list another one displaying the list itself, which gets updated automatically when a new book is added I'm confused about the way the relatio...
We have an internal library that does a calculation based on several datapoints. There is a fair bit of data required for the calculation, about 5kB in total. I'd like to make this an API endpoint for easier use across the org. But the calculation is idempotent and does not create any resources. I think this means it s...
I am creating a multiplayer game and was wondering if only the server knows about the actual players in the game, or is this list sent to the clients too? So for example the server knows about each Player's ID and NickName, in a list. Should clients also receive this list? Some potential use cases for this would be: S...
I work for a company that wants an external system built outside of their core system. I can't share an SQL database, and can't store data in their database. So I am forced to maintain my own SQL data that has relationships with the internal data. I am wondering how to handle SQL Foreign Keys and external data (examp...
I want to perform some operations on data class fields before accessing them and I am confused about which approach I should follow. I want to write code so that it makes sense to everyone and follows by experts so I want to know Is it good to make data class fields private and only let them access public fields by per...
We have two exit code code PAM_SUCCESS(0), PAM_AUTH_ERR(7). If we wanna return 0 or 7 when we compared password with our password in following code which code is better that this code ? if (strcmp (expected_password, crypt (password, expected_password)) == 0) retval = PAM_SUCCESS; else retval = PAM_AUTH_ERR; B...
I'm writing the sort of tests which go through a whole user scenario e.g. User clicks "edit profile" User edits their name etc. However, I find myself needing often needing to test small variations on the same workflow. For example (3) could be "User saves changes" or it could be "user cancels changes" etc. It feels ...
Suppose we have a BaseModel, which has a type enum, and derived models with same constructor signatures to each other, whose implementations are like : public DerivedModelJ(Object arg1, ..., Object argN) { super(Types.TypeJ, arg1, ... argN) } Now suppose that, when we use them, we want to hit a method that will retu...
This question might seem like a trivial question. But here it goes. Currently, I'm working with this .NET Core application, an N-tier application consisting of a Vue frontend, business logic layer, and a service layer. It's a medium-sized application with + 50 endpoints that the frontend connects to. From the service l...
I want to apply DDD to a pet project and everything fits perfectly except for one part: aggregates with collections and the need of pagination. I've been researching about how to deal with an aggregate that has a collection of entities that are too many to load in memory and, therefore, pagination is needed. I've found...
I was wondering if there is any downside to using E-Tag cache for every request and response. To be more specific, I'm building a data heavy SPA connected to a Laravel API and the client insists that he should be able to see 200 or 300 results at a glance. Although the data is text-only, it is quite a heavy network loa...
From what books I read on linux system programming, it seems like signals were the primary way to communicate events between processes. They were the gateway into many interesting functionalities, like timers, interrupting sleeping threads, IO events and so forth. When reading books on multithreading and latency contro...
Why I'm writing this question is to get more information and to gain more knowledge for state management and best practices. I have been using NgRx as state management on my angular 11 project everything was fine at least I thought like that. Generally how i implemented state management is in this file format: where f...
This may be a dumb question, but I don't know how to solve this. I am moving from CRUD to Domain-Driven Design with CQRS. I have seen many DDD examples like this. You could find many more on Github. The domain model has methods like changeDetails, addSomething, removeSomething, etc., and the commands could be just like...
I'm currently designing a new online platform where the frontend will be Angular using Angular Universal and the backend will be a sort of Node.js clustered microservices. The question itself is what is the best approach for the microservices: One clustered NestJS API Gateway serving the frontend with REST End points,...
Recently, at the organization I work for, we've been using a static code inspection tool. One of the more interesting findings is that private information, such as passwords, may be stored in the heap where it could potentially be intercepted by an application scanning the heap or perhaps a disk swap. The app being sca...
I want to understand the difference between business capability and subdomain Decomposition for mircorservices. subdomain The subdomain decomposition corresponds to Domain-Driven Design (DDD) subdomains. business capability Define services corresponding to business capabilities. A business capability is a concept fro...
I have a jar file, for example foo.jar. My code contains a lot of libraries (almost 75 jar dependencies). I am not using anything like maven or gradle, I'm just using pure java with pure jar files as dependencies, and I am working on my project in IntelliJ Idea. I used the IDE's artifacts system to turn my code into fo...
I am somewhat new to web development and maybe this question belongs to stackoverflow, but there is a human-interaction component here. Here is the scenario. I am serving some neural network models via an ASGI backend server developed via fastapi and deployed via uvicorn. So far as I am concerned, the server is working...
I have a question and answer trivia game app which randomly picks questions from a database and prompts the user to answer the question correctly. The total number of correct answers, the total number of questions attempted, and the elapsed time for the entire quiz session are recorded. What I need is a formula that wo...
We have unit tests that are running some underlying model. We provide it with some test input, and receive some outputs + floating point scores. What's a good practice from a unit-testing standpoint? Should we place assertions on the floating points themselves, or just check that they are within a good range (i.e. > 0....
In the below figure, a CD shop has CD cupboards, and inside it has shelves. CDs could be rented, and class CD Copy represents the actual CDs that are rented. My question is, should I represent Shelves as aggregation of CD copies or CDs?
I write code in R, and often find myself attempting to optimize the code for better performance. In a given script that tackles a specific problem, I test different code alternatives and compare them to each other with benchmarking. At the end, I select the most performant method. However, I don't know how to document ...
I have designed our in-house hardware testing framework. My goal is to ultimately release the framework into the public domain. Early on, my foremost design criterion was to provide a powerful yet easy-to-use test API for test authors. But I didn't want to neglect the test operators either (since they are normally not ...
I need to design the architecture of a CRM "platform" that integrates 5-6 legacy CRMs. One important feature is to show customer records stored in other CRMs in one single dashboard. The actual records are stored end edited in their own CRM. One question is: should I store a minimal set of information about those recor...
I've got a Window, which gets a viewmodel instance injected into its constructor. The window sets its DataContext to that viewmodel. The viewmodel contains a command to "submit" the window and a command to "cancel" the window. The commands are attached to buttons in the window (via a Binding expression in XAML). The vi...
I'm going through some code from this article about ECS-systems in game programming and trying to understand it, and something I'm seeing a lot is using heap memory in places where it seems like there is no benefit in doing so. Take this as an example: class ECS { public: void someFunction() { archetyp...
As this article explains the way to deal with persistent state in an event log driven architecture is to have some "microservice" subscribed to events and be responsible for maintaining that state, such as tallies of the weight of all green trains in the last 7 days etc. But I'm uncertain about how to implement conditi...
I want to understand the Domain-Driven Design approach, how it works, and what it includes in its Definition. TLDNR What is the mental framework behind DDD? What are the core components of DDD? How are the elements applied? Update I will keep updating this post after the helpful post. If you are like me and want to und...
In a document editor application, is it better to implement the command pattern as a layer on top of the object model, or to deeply integrate it into the object model? If commands are a layer on top, they would manipulate the object model using its regular getters and setters. Pros: Commands are higher level, represen...
I have been working on an application which consists of several cohesive services, Customer, Invoice, PurchaseOrder, Highlight, the application is deployed within a mono repo and each service is packaged within its own directory, in a package by feature arrangement. The application is serverless and each entity (aside ...
Certain OS in it's system requirement doesn't specify anything peculiar like in case of ubuntu it asks only for "2 GHz dual core processor or better". If yes, how does it compares with compiled code(C/C++)? I have heard that code compiled in one machine needn't work on another(even if same no of bits). Can anyone shed...
I've recenlty been greeted by CS8603 - Possible null reference return, which indicates that my code could possibly return null. It's a simple function that looks up an entity in a database by id - if it exists, it returns the entity. If not, it returns null. public TEntity Get(Guid id) { // Returns a TEntity on fin...
In C#, how do I handle critical section with two different "rights of way"? Theoretical use case: imagine a swimming pool (the resource). Many individual swimmers (worker threads A, B, C, and D) can swim into the pool as they feel like to, and its totally OK for multiple swimmers to be in the pool concurrently. However...
I have a C++ library that I'm converting to Python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of coordinate systems). In retrospect, these methods and constructors were rather ad-hoc, and, now after converting these t...