instruction stringlengths 34 36.1k |
|---|
Scenario:
An API that responds to a request with multiple JSON objects contained in an array.
The responses are paginated such that each page returns an array of JSON objects.
I deserialize the JSON responses into an object, then append that object onto a List (or some other collection), and then return the collectio... |
I'm building an infrastructural service with my team. We are building a service that will help other teams in our org send out a notifications to end users when certain events occur. We are currently having an issue agreeing on which service should be listening to occurrences of these events to then trigger a correspon... |
I have an ASP.Net Core Web API where I am having difficulties designing the REST resources based on the EF Entities I have.
There are three entities that describe a Reservation. First, there is the Group Reservation:
public class GroupReservation: Entity
{
public int Id { get; set; }
public string? Reference { ... |
Backstory
Probably a stupid question, but I just have a sneaking suspicion that "asynchronous" is the wrong terminology to us for naming my template function here:
template <class T>
auto asynchronous( auto &&lambda )
{
QEventLoop wait;
QFutureWatcher<T> fw;
fw.setFuture( QtConcurrent::run(lambda) );
QO... |
There are many version control systems out there, and they tend to use one of the following models to store separate versions of a repository:
Snapshots - each version of your repository is stored in its entirety, i.e. if you make changes to file1.txt, there are two stored versions of file1.txt representing the differ... |
Is there a best practice for managing shared state between a parent and child objects that is most likely to avoid bugs, maintain consistency, and be easy to implement/understand and maintain?
As a concrete example, consider a crossword puzzle solver. I'm envisioning the following objects:
CrosswordPuzzle
A grid wit... |
The Java project I am working on currently has a complicated folder structure, and to add a new functionality, one needs to add many .java files in different places in order to let it work in our project structure. For example, when I want to add a new object User, I need to add Entity, JsonModel, Controller, Listener,... |
Code in Python as example.
For instance I have an emoji class with following attributes and dunder method:
class Emoji:
def __init__(self, name: str, animated: bool = False, id: Optional[int] = None):
self.animated: bool = animated
self.name: str = name
self.url: str = url
self.id: int = id
def __e... |
In git flow, there is a point where you decide to create a branch from the current develop being the new release. For example 1.7. Everthing that is ready to this point is considered beeing in that release, everything after this point is a new release (e.g. 1.8). Only bugfixes should go into the current release branch.... |
I've already read this carefully, but still need more clarification.
I'm not new to dependency injection, but new to Hilt, and trying to implement Hilt in my multi-module app.
The reason?
I currently have a static application class wich not only provides a context, but also a singleton SQLite database, and it also hold... |
tl;dr is is a good idea for const methods to be able to mutate objects referenced as reference members?
Imagine you have some kind of work queue that uses items that look like so:
class Consumable { /* ... */ };
class Consumer
{
// ...
virtual void consume(const Consumable &);
};
struct WorkQueueItem
{
Consu... |
I want to create a git repo that will include scripts in /nfsdrive/sbin/ and the services that activate these scripts—which reside in /etc/init.d/.
I've searched the documentation and the relevant discussions, but could not find if the above is at all possible, much less how to accomplish it.
Is it possible to create a... |
In my job I work with C# (although the language is irrelevant for my question, and now I'd like to focus on Android) and we usually inject interfaces and not the actual classes, so I was wondering what are the real benefits of that?
As far as I know, I can understand interfaces (if no DI is taking part) as a way of not... |
We have a scenario that is in a VERY tightly controlled industrial environment. This is all C# on Windows.
We gather data from different types of sources - sensors monitoring environmental data, sensors monitoring production line stats, sensors monitoring production line health, etc - with specific "service application... |
Well, I'm developing a personal project using TDD and Clean Architecture, and I chose to build an abstract class to gather all use-cases behavior in one single class. My question is: What you think about making test for this abstract class? Would you write tests only for its subclasses or would you do a "mock class" ju... |
I want to illustrate my problem statement with a use case. I am building a trading system that acts as a container for deploying trading strategies. The trading strategy comprises dependent tasks. Let's suppose there is task T1 and T2. T1 runs at the market open (the core of the strategy), and T2 runs after the market ... |
I design a common API for selected printers of different brands in Java. Each printer uses a different underlying SDK with different functions, but any hardware my code runs on will have only one printer connected, this is a known guaranteed hardware limitation. Despite dealing with different SDKs, I also have common l... |
There are a few threads about how to handle the version number with semver upon changes in dependencies (usually resulting in a +1 to the patch number). Mine is probably a corner case: what if you are just updating a development dependency (e.g., a linter, a test library, a formatter...)?
Usually, from the user perspec... |
I've gotten this idea in my head that i shouldn't use a libraries variable, if the variable name begins with '_', as it is standard to write private variables that way.
But now i'm thinking i'm taking that too literally. If my choices are to use "_var" that points to a HTML element or add a unique attribute to said ele... |
I have not previously designed a nontrivial HTTP API, so I apologize if anything here is textbook stuff. I wasn't able to find anything going into this in much detail when I looked.
Let's say I have an API where you can upload some data and then request a potentially long-running operation be performed on this data. ... |
I am a very beginner writing one of my first webapps. I'm using FastAPI and I'm stuck on the logic of creating an endpoint that has to do a lot of things before it returns something back to the user. Since I'm new I also lack a lot of the vocabulary that I think I'd have if I were more experienced so bear with me:
To s... |
I have a segment of customers which may range between 1 and 5000. For each customers, I need to do some processing by making some query to the database using the data from the customer. The query is expensive and is the reason why I plan to use a queue to handle these tasks.
I figured a simple queue with one producer a... |
I recently started learning about DDD and I'm in the process of designing my first solution.
I have a business requirement to design solution for Auction module and there are many types of auctions like car auction, property auction etc. all auctions types share same set of properties with custom properties to each typ... |
I feel as if i am over-thinking this, but with a RESTful API design with resources being themselves resources of something how should these 'typically' be accessed?
Of course, an acceptable answer is 'it depends', but i am trying to understand what is usually what people might expect, and then also what is easiest to r... |
With the purpose of learning Hilt I started "migrating" my multi-module Kotlin app from using classes with static methods as helpers to Hilt injection.
After a lot of headaches, now everything's going fine, and I could say I'm happy and in the 80% of the migration, but suddenly a question have come to my mind and stopp... |
I recently started learning about DDD and I'm in the process of designing a solution for an Auction module the issue I'm facing is that the different types of auctions have different characteristics for example:
I have Auction for License plates and when creating the Auction you should provide the base letters like "AA... |
I have different availability requirements (90%, 95%, 99% guaranteed uptime) for certain subsets of data. For example, the subsets of data are split based on the possible values A, B, C.
What would be a good way to do this? Guaranteeing 99% uptime for all sets would be a waste of resources and too expensive given the r... |
I have a colleague that insists refactoring to make the code testable and introduce tests should be independent from changes in architecture as part of refactoring, e.g. introducing a factory pattern. They think that such design decisions, like introducing a factory pattern, should be conceived and discussed with the t... |
I've just started dipping my feet into OOP.
Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'm self-taught so trying to gauge what is considered better quality. Any mistakes are easily fixed by just making sure I... |
I am working on a REST API for a company that, until recently, has been focused on the Australian market. The result of this is that the API has resources and fields which model the Australian market, especially in relation to taxation, superannuation etc. We are now looking to move into overseas markets, starting with... |
I have an MVC application in Java with GUI components in a View class. The GUI has to support two languages, so texts on buttons etc. depend on which language was set at start up. Strings are in .properties files and I have a MyStrings.get(Key) to get the string corresponding to Key.
Should I call MyStrings.get(Key) in... |
I have an issue regarding the differentiation between two Rest methods that have the same amount of path parameters:
@GET
@Path("image/{ratio}/")
@Produces("image/png")
@PermitAll
public Response getImageMe(HttpServerRequest request, @PathParam("ratio") String ratio) {
//Do something
}
@GET
@Path("... |
I was reading some of the documentation for the linux kernel and I stumbled upon an article about adding new syscalls to the linux kernel. The article essentially says that any syscall in the linux kernel must be supported permanently:
A new system call forms part of the API of the kernel, and has to be supported inde... |
I have never used atomic operations, and remain largely ignorant of how to utilize them. And yet, I often come across objects like this when peering into Qt's backend:
https://doc.qt.io/qt-6/qatomicinteger.html
This leads me to question if there is a feature here that I have not been properly taking advantage of.
My qu... |
Let's say some method of a parent class is reimplemented in a child class.
This child method is intended to do the same that the parent method, with a minor change.
In this case, in the documentation of the child method, is it useful to cover what the parent method do ?
If we do, the child method is 'self-supporting' ... |
I have a decently sized registration form that will require some PII data, as well as some obscure shipping information. I am working on best UX practices for input repopulation considering the time and effort needed for the form. I was curious if storing address info in localStorage, when there are no ties to a part... |
I do know that the best practice these days is to model immutable classes in Java. An ex: below
// It makes sense to model this in an immmutable fashion
class 2DPoint {
private int x;
private int y;
2DPoint(int x, int Y) {
this.x = x;
this.y = y;
}
public Int getXCoordinate() {
return this.x;
}
... |
I apologize for asking this intuitive question. I'm not good at programming and my recent work requires me to work a lot with SDEs. I wonder what might be the advantages using the this pointer?
I understand why it exists, and sometimes "this" makes it clear we are assigning value to a member variable (in the following ... |
I currently have a CI workflow for tests that use data present in my repository. However, since this data is very large, I would like to move it to another remote repo and somehow give my CI tests access to this data from that other repo. One way I could do this is by using git submodules, but that would still force me... |
Suppose I have a member function void A::foo(B const &b) where a class B instance is just a bunch of data. Would it not be better to remove the dependency between class A and class B by rewriting the member function like void A::foo(int var1, double var2, double var3)? Or could this modification be classified as a Prim... |
A seemingly basic question here.
Is there anything you can do with multidimensional arrays that you can't do with nested arrays?
Many languages have been designed with both facilities and syntactical differences, but I can't for the life of me work out what you can do with multidimensional arrays that you can't do with... |
Sorry my title is terrible i couldn't think of a concise title to use.
I have a bit of code that needs to consume two quantities from two objects, this is done using a TryGet() type of method and the code looks like this:
if(A.TryGet(resource, total) && B.TryGet(resource2, total2)){
//do what ever
}
The problem is... |
Programming languages traditionally have blocks that specifically cater to controlling iteration.
There is the simple while-loop:
while (i < 3) {...};
Then there is the more complicated for-loop:
for (i = 0; i < 3; i++) {...};
There are others, but these examples are sufficient to illustrate a point, which is that a ... |
I was working on a unit test that has a mock object looking something like:
public class TestMock
{
static {
Doodad a = new Doodad(0);
Doodad b = new Doodad(1);
Doodad c = new Doodad(2);
Foobar x = new Foobar('x');
Foobar y = new Foobar('y');
Foobar z = new Foobar(... |
This is a follow up/related question to a previous question I asked regarding Interface Segregation. I'll build up on the same example, providing a bit more context.
In the game I'm developing, a card is structured in the following manner:
A card must have a primary ability
A card may have an "ally" ability. If it doe... |
I'm currently working as Fullstack developer, our frontend is being built in React.
Our current process involves:
The client / product owner describes a feature to the UI / UX designer.
The designer creates a nice template in Figma, or any other UI tool like-so
The design is given to us the developers to implement
The... |
I've written an implementation of the UCT1 Monte Carlo Tree Search algorithm for selecting moves in a two-player game. In the future, I'd like to expand this implementation to use more advanced tree search techniques like RAVE to be able to search more efficiently. I'm trying to figure out how to write unit tests for t... |
for example:
const arr = [1,2,3,4];
const coordinate = [arr[0] + 2, arr[0] + 1];
here arr[0] is written out twice, when the code is executed would it literally go and find same value twice or would it remember it?
Does it matter that arr[0] in example above is used in the same expression? What if I would use arr[0] i... |
I'm not sure how to best ask this, as it's the first time I have to tackle such stuff. It might be that it's a common problem and I'm just using the wrong keywords to search. Basically, imagine a microservice needs (as part of its data) the ID of some objects managed by another microservice. For example, Users and Orde... |
Consider a microservice architecture composed of a number of asynchronously communicating workers. Each worker deals with an isolated task and may have its own specialized database. Now consider that the services are meant to work on a common task by starting to do their specific computation and, once finished, contrib... |
I am looking for a better approach to add multiple products to my db.
(things I have tried)
Example 1
[table
Products - ProductId pk(
ProductId,ItemCode,Price,ProductType)..]
[table 2
Frame - ProductId pk(
ProductId,FrameType,FrameSize,Glass,Mat,Spacer)..]
[table 3
PrintRoom - ProductId pk(
ProductId,Material,ImageSize... |
What's the difference between an API and a protocol?
To use a specific example: Is Coinbase's choice to refer to its WebSocket client specification as an "API" appropriate? It seems that many companies in their space followed their naming trend. For example, FTX calls this client specification their WebSocket API. This... |
Let's say I have a REST API that needs to return the width of an object, but that width may either be a specific value or a range of values. What would be the best practice for designing the API to handle this?
For example:
"width": 35.5
"width": {
"minimum": 34.2,
"maximum": 36.8
}
Would it be best to simply spe... |
I am trying to understand layered architectures and apply some DDD fundamentals to improve my architecture. I am finding that determining "what" an application service actually is, what its bounds are and what questions it should answer is really hard. Similarly for domain services.
Overall, I can't quite comprehend th... |
I have a C4 container diagram of a system, in which most of the components communicate with MQTT. The MQTT container is SOUP. Is it necessary that I draw the MQTT container or can I simply draw direct relations between containers and state on those, that it works via MQTT? Is there a specific recommandation? If yes, wh... |
I've come to a bit of an impasse with the best way to implement a DDD problem, and am hoping for some advice from those with more experience, please.
I have a RecipeCollection, which has a collection of type Recipe (as you might expect). The abbreviated code looks like this:
public class RecipeCollection : IEntity<Reci... |
I want to understand how does Spring Boot and Postgresql DB handle the concurrent requests for updating a value in DB. Consider this example of facebook likes, if there are multiple instances of application running and each of them are getting multiple requests concurrently for a like on post, currently the like is onl... |
I find myself in a situation where I have two roles, "Admin" and a "Organizer". The "Admin" accesses the AdminUserController to update users, while the "Organizer" accesses the UserController to do so. This is important since the user indexing and input validation is different in both cases: the organizer only indexes ... |
Context
I'm giving a try at my first backend API which aim to follow some Domain Driven Architecture concepts that I've learned from an implementation in Go in a Udemy course.
The problem is that I don't clearly see the role of the Service.
In the course I've followed, there's a users-api microservice and an oauth-api.... |
I am reading about DDD and in the examples it is common to see how the domain gets the data from database, do the business logic and then persist the data. For example to update a field:
class MyDomainClass()
{
//Dependency injection of the repository
public MyDomainClass(IRepository paramRepository)
{
... |
Repositories in ddd should give the illusion of an in memory
collection.
and
A Repository is essentially a facade for persistence that uses
Collection style semantics (Add, Update, Remove) to supply access to
data/objects
I've read contradicting examples on what repositories are supposed to be:
abstract class Order... |
I have an issue where I have multiple databases from previous projects that I would like to combine into one large database. These databases are stored in .sql files. The issue is that I only need specific columns and information and I'd like to filter out any columns that aren't the ones I need. Some of the databases ... |
In domain driven design
A repository is a collection like "interface" that hides data source access. It furnish add, remove and retrieval method just like a collection would. It does it using domain language.
The application layer uses the repositories by thinking about them as collection, by retrieving from it or ad... |
I'm studying Clean Architecture with python and got into this "problem" of choosing where to implement a rule (that I considered a Business Rule, maybe I'm wrong)
I have 2 Entities
@dataclass
class A:
bs: List[B]
id: Optional[str]
# ...
def add_b(self, b):
exists = next((x for x in self.bs if x... |
I've been using the publish-subscribe pattern for a while for communicating devices and it works really well, making it easy to add extra services without touching the rest. I'm thinking of using it inside an application (think of a monolith or a GUI application).
The basic idea is: every component can subscribe to any... |
I'm working on an accounting service. I have to generate invoice for a user and upload it to the file storage. So my service would have to use a service from file storage team. File storage service and Accounting service are on the same layer level. File storage is a generic subdomain, while accounting is a core domain... |
I'm trying to design a monolithic application following DDD and clean code. Lets say I have Users, User Types, Products, Product Types and Purchases. I want to implement using different modules.
At the moment I'm thinking in Users, including the user types, Products, the same including the service types, and Purchases.... |
I am trying to understand the advantages of service discovery compared to load-balancing within the context of a microservice mesh where many instances/nodes/VMs/containers of many web services are all calling each other in a complicated web-pattern. And my understanding of the situation is this:
Service discovery -- ... |
We have a feature like "new command-line query tool" and stories like:
As a user, I can do X
As a user, I can do Y
As a user, I can do Z
Where/how do I detail "create the test harness application"? The stories focus us on what is needed but whichever one we do first, the developer will have some setup overhead.
Would... |
Note: This is a contrived example I came up with to illustrate what I'm after as simply as possible.
I have an HTML report with a single dropdown box at the top that lets the user select (or filter) the data that will be returned. However, the dropdown box doesn't contain a single type. It contains multiple types, th... |
OSS API Gateways typically come bundled with built-in load-balancing capabilities. We see this with Netflix Zuul and Kong.
In a service-oriented architecture, where many microservices are talking to many others, is the idea that each service has its own API Gateway, with its own load balancer that can serve traffic to ... |
I am working on a project and created multiple lambda functions and now I am thinking about whether I made the correct decision to go this route.
Reasons I chose lambda:
The App will have spiky traffic and almost no traffic at some times, so it is cost-effective
It seemed like it would be less stressful to update part... |
I may be overthinking it, but are controllers and resolvers the same thing in web applications? Coming from the MERN stack, everyone used to call these request processing functions "controllers," but in PERN+GQL, everyone calls them "resolvers." By my understanding, they are the same thing.
MERN - MongoDB, Express, Re... |
At the moment I'm spending more time planning out a commit than actually writing code when adding a new feature. Less than two hours would be lucky, and sometimes I'd spend a good part of the day without writing any code. This is making me unhappy, since I don't feel I'm productive enough (I'm living with my parents, a... |
I have just recently joined a new company and one of the classes used to log information has not been written properly. So I have been asked to add new functionality to the logger.
Rather than amending the Logger class I want to follow the O in SOLID and extend the class by creating a derived class and adding functiona... |
I am building a small application that supports a research project. My goal is to make the code to be painlessly executable and readable on as many operating systems as long as possible.
My reasoning is that 2-3-5-10 years down the line I will work on a completely different research project, but my software may have to... |
I am a full stack developer who's been learning about Domain-Driven Design in the past couple of days, so I have some question since I have trouble finding place for this pattern in my applications.
I think of front-end as this reactive programming "experience" focused on UI/UX, and of back-end as a transactional, perf... |
We are revisiting how we do observability at my organisation, and I'm reading about Service Level Indicators (SLIs) as a way of measuring how our systems are performing. But what I'm struggling to get my head around is how this differs from Key Performance Indicators (KPIs) that I've heard others speak about?
They sou... |
I went through different ideas about storing AES key for encrypting database columns, I learnt that there are the possible solutions:
put the key in the database
find a Key Management Service to help you keep the key
Below is my suggestion:
prompt the user to input the key everytime he/she uses the database, it is a... |
I need to implement the following scenarios at the server:
User sent too many answers in a given amount of time, for example, it can't submit more than 3 posts within an hour.
User sent answer with the same text already, to prevent spamming.
My question is what is the correct way to implement client/server communicat... |
After my team went all-out on the microservice paradigm with an emphasis on message passing, I'm having trouble defining and keeping track of all the events in the system.
I've read some guides on the event-driven architecture, and while I get that the messages themselves should be as simple as possible, it still leave... |
Is it a bad approach to add domain logic inside typeorm entities if following the domain model pattern to organize business logic.
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Colum... |
I am building an API that (I am deliberately simplifying the schema below to only focus on what is questionable):
I have a table that roughly looks like this:
CREATE TABLE IF NOT EXISTS some_table
(
id INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
user... |
I was reading the documentation about how to use Entity Core in a DDD way. This is the documentation.
It is said that I can configure EF to can map an internal private field to a private field, the backing field.
The code is this:
public class Order : Entity
{
// Using private fields, allowed since EF Core 1.1
... |
I think my problem is very common but I couldn't phrase it correctly in the title.
I have a Django API that returns some information about companies (like address, partners, situation, etc) given its unique identifier. I would like to run tests on it because it is very unstable given that it depends on a lot of data th... |
I'm designing an algorithm that matches entries based on some notion of "proximity" (for the sake of discussion, assume we're matching floats). Furthermore:
The input is a scalar and a vector, and the output should the "closest" element of the vector to the scalar.
I'm considering three matching techniques: Forward, B... |
There're certain things in code that can't be conditional. Two very common examples:
static types
dependencies.
You can't naturally enable/disable a feature that implies a new dependency or a new type with a condition (a feature flag).
How do the proponents of trunk-based development tackle such cases?
package.json
... |
I have a program that runs on command-line, let's call it myprogram 1.0.1. It's published on GitHub.
Now I discovered that name already exist for a well-know software, so I want to change the name from myprogram to myprog. This, of course, will break the old usage of command since the user now must type myprog and not ... |
We are a small team contributing to our startup project, on a daily basis the code changes and multiple PR are raised daily. The general issue we face while reviewing these PRs is the code formatting changes due to different IDE or the same IDE with different code formatting configurations.
Is there a possible solution... |
I am writing a Spring Boot REST API using JPA, so I have my application layers consisting of
controllers
services
repositories
entities
models for request, response, DTOs
This question is mainly around entities which often have relationships among themselves.
For example, a @OneToMany relationship to map to database ... |
So I was sending code for review and approvals for some changes I made recently. that includes a class as below:
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class UnKnownClientException extends CustomException {
public UnKnownClientException (String message, Throwable throwable) {
super... |
I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters.
To provide a simple example, I would use two polynomial classes, please, don't give an answer specific to polynomials, e.g., saying that one could just create the generic class polynomial,... |
I am currently working on a small web-app stored in a monorepo and using PSQL as database (hosted on GCP). It's my first time working for a web app and I have to create a lot of tables manually such as using this script to create the positions tables:
CREATE TABLE PUBLIC.positions
(
position_id INTEGER NOT NULL... |
I'm trying to understand CQRS, DDD by writing a small pet project which is somewhat similar to this great repo.
I've come across Transactional Outbox pattern and as imo it was correctly pointed out in this article it looks hard to scale this approach to even thousands active users when using document oriented databases... |
My company develops many relatively small projects that a lot of times do the same things and have a similar structure. (e.g. read/write to a databse, data pre processing, building a query etc.). This creates a natural urge to create libraries and frameworks that either implement some of the repetitive logic and/or for... |
Say I want to implement a mathematical tool or simulator for mechanical joints.
There are different types of joints (revolute, prismatic, etc).
Which have different properties (degrees of freedom, constraints in a 2d planar system, constraints in a 3d spatial system, etc).
I can think of multiple ways to implement this... |
I am building a bank management system using the microservices architecture. I have many microservices but I am going to talk about two. I have customer account service and transaction service. Let's say a customer wants to perform a transaction(deposit/withdraw/transfer) should I define my api in transaction service ... |
I'm looking for some advice on a system I'm designing, at its core it will allow users to create/join/manage groups of users.
I thought it would be a good idea to try and apply some DDD principles, which has led me to create following domain models, I'm currently treating a Group as the aggregate root.
public class Gro... |
I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, if the move is valid but there is an opponent piece on that square then the piece is trying to capture not just move.
I b... |
I was reading a bit about garbage collectors and I am wondering if the garbage collector of a program scans the entire heap memory or what is allocated to it? If it reads the entire system memory, does it mean it is reading memory locations that are used by other applications? I understand that this does not make much ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.