instruction
stringlengths
34
36.1k
LocalDTO term refers to Fowler's article. Say I have a domain entity Person: public class Person { private String id; private String name; private int age; } This entity has its own semantics in the domain & application layer and has its behavior. In other words, it is not an anemic model. Now I have a pre...
I've tried Googling this using several phrases and I simply can't find this asked anywhere so I hope this isn't too silly a question. I'm just dipping my toes into DDD and I have a toy project I'm building around Defi in the crypto space. In short the point of the project is to read a bunch of information from smart co...
Not sure if this is the right forum for this, but I've come across a need for this pattern a few times lately, and I would love to get some opinions on options for how to handle it. Say I have an app that takes data from an arbitrary number of third-party applications and wants to parse it into a unifying format: { ...
I'm building a use-case for creating blog posts, at first I thought of using an entity as a use-case parameter, and this entity would be created by the layer that calls Use Case, in my case a controller. Controller: //.... public function createPost(request: Request): void { const imagesToUpload: string[] = request...
I've been going over the Visitor Pattern to try to understand it. Is this a correct implementation of the Visitor Pattern for RPS?? Here's the implementation code: public enum ResultEnum { WIN, LOSE, DRAW } public interface ElementVisitor { ResultEnum visit(Rock rock); ResultEnum visit(Paper p...
Let's say, there's a Product data-model. Product has the attribute - colour, which can, in this case, be red, black, yellow, white, orange. And which in total amounts to 5 different Products. Now I want to introduce a new set of attributes, let's say, material - cotton, nilon, paper; and size - s, m, l, xl; this will a...
I am working on a JavaScript tutorial series for someone who has no experience coding. The format of the series is that it is a public Github repo. Each lesson is a README.md markdown document, and ends with an exercise. The exercise is usually some Jest tests that I've written, and the student needs to implement some ...
Since I am working in a multi-instance microservice environment, I came accross a problem with making some operations being performed at most by one of the running instances at once. The solution which we used for this up to now was to have a mutex lock stored in database, that would prevent other instances from doing ...
When I joined my company as a new comer and I was exploring the unit test suite of the product code. It is using gtest framework. But when I checked all the tests, they were testing the whole functionality by calling real functions and asserting expected output. Below is one such test case as an example: TEST(nle_26, U...
I'm building a client for an API. The API takes a query param that looks something like this 2-10, that's a range and notice that it uses a hyphen (-). Usually, data comes from another place using en dash (–) instead of hyphen. If the api is called using an en dash instead of a hyphen, it will return empty, so we need ...
I am trying to work on finding the following metrics New Work - totally new code which does not replace other code. Churn - code that is rewritten or deleted after being written Help Others - where developer helps on someone else work While I was working on churn and new work metrics, I cam to know about legacy refacto...
I am currently developing an API that returns JSON structures. One of the domain objects returned is a time series, which is a potentially large list (many thousands of elements) of complex objects. Say a time series element consists of value and status, there are two ways to represent this in JSON. Either as a list of...
The other day, I came across this question on StackOverflow. In short, the user who asked the question wanted to extend a class from a third-party library to implement the Codable protocol, but another library had already defined an extension to do just that, and the user preferred his own implementation. I come from a...
I know debugging and bug fixing are related and generally, bug fixing is considered as a subset of debugging (for example here in Wikipedia, "The process of finding and fixing bugs is termed "debugging"), but I wonder wether these two terms can be used instead of each other?
I have a database with a 1:m relationship. I have to display a list of parents to the user rapidly on a home screen at startup. The parent shows a single piece of information that is a sum of a particular child field for that parent. I don’t want the expense of making large queries to the child table (essentially doin...
Let us say I want to store on a database a userID, their nationality and if they are from the UK their UK passport number. I could model this by having one table with userID as primary key, nationality as an attribute and the Uk passport number as an attribute , which exists only when the nationality is UK. As an alte...
I hope this question isn't too vague because it's more a discussion than a question. I want to write a code which can detect physical violence in a scene (with the end result being the prediction of triggers in the movie/show). I would like to do this through python (however I'm open to ideas of other codes- I'm famili...
As the title states, I'm wondering if my current architecture is currently too granular. Additionally, I'm curious if I should be pursuing a microservice architecture in the first place. For context, I'm building a multi-tenant document generation system and I currently have the following entities: Tenant Template Doc...
Thanks for reading my question. I have a class which reads a configuration and based on the configuration, populates a data structure by reading from a database, which is ultimately presented to a processing layer that makes use of the data for various processing. Configuration: <FieldConfigs> <ConfigField name="My...
I studied systems analysis and design (SAD) in college/university, which primarily gave a set of methods to design a system, using UML diagrams. Flow charts, entity-relationship diagrams, etc, were used to take an idea or an existing/paper-based system and come up with the design documents for developers to create the ...
We have a standard microservices setup (Identity Server, API Gateway, services, etc). Some of the services schedule events to be dispatched in the future (future = anything from mins to months ahead) - the underlying mechanism is an AWS SQS queue. We are looking to implement a feature that means that something might h...
I have implemented an append-only tree data structure as a class in C++20. Internally it uses std::vector<Node<T>> where Node<T> contains an int parent_index and T payload. A node without a parent has parent_index = -1 as special value. I am wondering which integer type would make the most sense here. I have good argum...
There is a minor difference between Saga pattern https://microservices.io/patterns/data/saga.html and my use case below. Saga pattern is about distributed transaction when an event is happening vs my use case below is a reconciliation pattern after events have all happened. We have a large ecosystem of microservices (3...
I am developing a Spring Boot Application which consumes another REST service to get the User's Account information. The same service provides multiple operations like: GET: /userid/retrive -to get user and account information POST: /user/create - to create a new user POST: /userid/save - to save the user information ...
I have a list of product price objects, List<ProductPrice>. @Value public class ProductPrice { Long id; LocalDate startDate; LocalDate endDate; BigDecimal value; } From the list I need to find prices that have a start date equal to or greater than a given start date AND an end date equal to or be...
I wanted to know when you are done processing some query or transaction do you usually close a connection only? do you close the pool? or do you close both? Does it even matter which one you close? What happens under the hood when you do all three of these cases (if there even is a difference). I’d appreciate it since ...
Consider this schema in a relational database: There are two tables A, B, both having two columns X, Y. The constraints are: X in both tables are the primary keys. (The values are unique in each table.) The data in both tables must be exactly identical. (Each insert, delete, update request must be applied to the two t...
It has been said that "PUT is idempotent": The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), whereas successive identical POST requests may have additional effects, akin to placing an order several times. How do I...
I have a RESTful service where clients provide product codes, start date and end date. In response, the service returns a list of price metrics for the products over the date range. Start date is optional. If not provided, price metrics for standard periods are returned. The data is captured in PriceMetricsDto objects ...
I have a suite of python Azure Function Apps that all together make up an integration, each containing multiple functions: FunApp1 func1 func2 SharedCode FunApp2 func3 func4 SharedCode FunApp3 func5 func6 SharedCode ("SharedCode" is legitimately shared code, but it must be deployed with each Function App, pe...
What commit type should I use when I'm deleting files from a repo? I have seen several types over the internet, but none talk about file deletions. Possibly the closest options that come to mind are CHORE and REFACTOR. EDIT 1 : START Reasons why I'm confused is because none of the definitions for CHORE and REFACTOR tal...
In JavaScript, if I have try catch blocks in a function that is meant to be called from another function, should I also put them in the calling function or just let the called functions handle them. Here is some pseudo code to illustrate what I mean. I have two called functions, one and two. They are essentially the sa...
We have capital-U Unit Tests that are supposed to be testing a particular slice of our code. This code has a dependency on an IConverter<TIn, TOut> (a wrapper similar to AutoMapper). The behavior of this converter is important for the overall system, but not for the behavior of the specific unit under test. The code ...
I'm building a Use Case for creating blog posts, this Use Case has its own "DTO", which is basically a parameter object with only primitive data, as follows: Use Case's DTO (Parameter Object): export class CreatePostInput { public id: string; public slug: string; public title: string; public authorId: string; ...
Suppose I am buying coffee. There are several types of coffee (A1, A2, A3), but sometimes I want to make a reference to all types of coffee (like if I had a coffee "grouped"). Considering DDD concepts, coffee A1 is different from all types of coffee, so that's their identities and I need to reference both specific and ...
I'm building an API in C# .NET that needs to supply the client with some data and an image. The image is stored in Azure Blob storage. Which is more efficient: Retrieving the image on the server side and returning it as part of the API response Returning the path to the image along with the data in the API response an...
Our company have a support team and a dev team. We require reproduction steps on every bug report, however sometimes the support team submit reports without and become frustrated when dev close them as "cannot reproduce / cannot fix". Support then make the argument "if I take my car to the garage, the mechanic will lo...
Let's say I have few entity classes: class EntityA { LocalDate date1; LocalDate date2; } class EntityB { } class EntityC { LocalDate date1; } and I want to pass them through some logic containing lots of conditional checks. Simplified version of something like: public class Predicate { public boolean test(EntityA...
I work at a rather small company, around 10 devs and we are facing a lot of problems with merges and so on, I figured it could be because of the amount Hotfixes we are merging into master daily. So I was thinking about one release branch per day, where it would be on origin and whenever a dev must do a hotfix, they wou...
In the red book by V. Vernon it says about REST: In RESTful HTTP, the methods are the HTTP verbs - most importantly, GET, PUT, POST, DELETE - that can be applied to resources. Even though it might appear so at first sight, these methods do not translate to CRUD operations. It is very common to create resources that do...
We all know that if we delete a file, the operating system is recycling it but doesn't actually delete it. It just removes it from the directory indexes, and until the data is needed and overwritten, it will still remain there. Recently, I have written a program that can wipe a entire hard drive. The program reads exis...
I use TypeScript. When I write the below code ESlint throws this error: https://eslint.org/docs/rules/class-methods-use-this export class { constructor() { const result = doCalculations() ... } doCalculations(): number { ... } } So I have 2 options. Make the function static. Move the function out...
During unit testing it is possible to estimate the code coverage to see which share of the code base is covered by the tests. For one part (the simple calculatable one) of a risk estimation we need to estimate the impact when a single line or a variable changes on the code base. E.g. if a variable changes and a pointer...
Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final String O_NAME = "oName"; public static final String O_TYPE = "oType"; public static final String S_TYPE = "sType"; pub...
New Design: We are porting Legacy code to C#. We have Request and Response Data Contract for each set of Business Data. These are POCO generated using Schema of External vendor. We will be creating 30-40 such Classes. We have no control over the structure. Hence I extended these classes with ToModel() and FromModel() ...
My understanding is that every PRNG or QRNG requires a state to prevent the next item in its sequence from being too predictable; which is sensible, as they're all running on deterministic hardware. GPUs are, by design, non-Von Neumann architectures which are incapable of remembering past operations, predicting future ...
I have the following problem: There is an amount of nodes each containing elements of different kinds. Each node has a max amount of elements it can hold. I want to sort the elements between the nodes so that they are grouped by element kind, rather than scattered between all nodes. To execute the sorting I can do swap...
Effective Modern C++ recommends using void futures as a way to communicate one-off events from one thread to another. Below is a minimal reproduction of that practice. std::promise<void> promise; void detect() { std::thread latent([] { promise.get_future().wait(); // react } //...do some work promise...
I'm practicing test driven development while implementing a network simulator: devices communicate with each other and implement little bits of functionality that respond to messages. Each device has its own view of the network topology and can be individually powered on or off. Timing is important. If the Device is in...
I'm looking for architectural guidance. I've got this monolithic application. It has a payment platform functionality, where payments are made, scheduled or on demand, via some banking API. Payments used to be stored in DB, along with all relevant info like banking transactions, etc. Making the payment is inherently un...
I am trying to maintain proper code organisation for my codebase. I came across a situation whereby organising my code into class A, B, C is unnecessary as class C can be incorporated into class A and B. This is because the functionalities in class C are from a library which means the functions have been wrapped nicely...
Throughout this semester my classmates and I had to do the pre-coding(?) phase of a project (requirements and such) as part of our Software Engineering course. The way our professor had us do it seems odd to me and I'd like your input. First we were given a document with the problem and had to extract requirements from...
I have 2 kinds of objects in my system, Car and Road. A Car can be of various types and have properties like tire, tire size, engine, etc. A Road can be of multiple types and have properties like terrain type, slippery, etc. Some type of cars cannot ride on certain roads, based on the road properties and car limitation...
I have an enum that works very well to represents date periods and the number of months in those date periods: public enum StandardDatePeriod { ONE_MONTH(1), SIX_MONTH(6), ONE_YEAR(12), FIVE_YEAR(60), TEN_YEAR(120); private final long offsetInMonths; private StandardDatePeriod (long offse...
Recently I had my first experience writing a wrapper around FTD2XX driver for a desktop tool that communicates with an embedded device. The library provided some common device specific functionality and encapsulated low-level MPSEE and board specific configurations from the user. While writing this library I found myse...
I have a scenario where I have to route a list of messages that I get to respective users. For suppose if I have messages = [ { text: 'hi', user_id: 1 }, { text: 'hi', user_id: 2 }, { text: 'hi', user_id: 3 }, { text: 'hi', user_id: 4 }, { text: 'hi', user_id: 5 }, ]; I read in a blog where creating queues d...
I'm making a naval warfare strategy game, based on a boardgame, in C# and having difficulty finding a good way to construct my complex ship objects (I am a beginner in the language and OOP). Currently, each ship class inherits from an abstract base Ship class that implements the interface IShip (code below). This inter...
In a pretty big project, I have a hierarchy of objects, let's say: Zone object, which contains Block objects and Connection objects. Mainliy, the Connection object links together several Block objects, all inside a Zone. In this project, I am using the Memento pattern (together with the Command Pattern) for implementin...
I am writing a library to allow two people to play chess for a toy project. For what is worth, it is in C++. I have deemed useful to have a class named Move, which represents a move which needs to be annotated in the history of the game. Objects of this class would provide the same information as an annotated move in a...
I find myself in a situation with the following implementation. I have a class that is exposed to users. My intention is to expose a high-level abstraction to the user rather than internal details of my library (or details they would need to handle without this library). An user can call some method named do_this_for_m...
Let's say I have an instance of a superclass and at a later stage this object needs to be converted into a subclass instance (based on additional information that are stored in the object). Is it acceptable to have a subclass constructor that takes a superclass object as an argument? Edit: A small but important detail:...
I'm reading Algorithm Design and Applications, by Michael T. Goodrich and Roberto Tamassia, published by Wiley. They teach the concept of primitive operations and how to count then in a given algorithm. Everything was clear to me until the moment they showed a recursive function (a simple recursive way to calculate the...
I really don't love the design pattern I've established here. It's kind of DI but not really, and the alternative is more constructor based DI, but I also hate it. Maybe it is because it is JS and that's just the way she goes, but I was hoping for a second opinion or a better pattern. Basically I have an app, that has ...
I have a pull request and this pr is being reviewed by co-worker. Context I'm using React and a specific component has ternary operator within component like below. const ExampleComponent = (): React.ReactElement => { return ( <div onClick={condition ? handlerA : handlerB}> <span>{condition ? textA : textB}...
I am designing a somewhat complex flow in publish subscribe pattern using AWS SNS, SQS , Microservice and Lambda functions. To break the whole flow into multiple logical & smaller sub-flows I am trying to accomplish that through publishing messages in different steps of the flow. But it seems the same microservice only...
Is it an anti-pattern to extract common configuration code as a library and reuse it across microservices? I am breaking down a monolith app into a few of microservices. What I stumbled upon is: since it is a monolith there's already one single point of e.g. security configuration (enforcing authentication on all endpo...
I have a class that is mapped using Entity Framework. This class has dozens of fields, and in the database there are millions of rows for this class. The class looks like this public class MyEntity { public string Key { get; set; } public string ImportantField1 { get; set; } public string ImportantField2 { ...
I want to know how standard I/O channels are handled in more depth. Processes have their own stdout, stderr, stdin channels where they can read/write. As far as I know, these are stored as temporary files at least on Linux, not sure about Windows, but the point is how does a process know where is another's stdin in the...
I'm the sole developer working on multiple projects on different versions of Java, plus some Microsoft Sharepoint front end projects. I REALLY need to figure out a better setup for my development environments and would like to know what others use. Please let me know if I should be posting in a different stack* communi...
I am working on removing obsolete/unused pieces of configuration from a .NET product starting with appSettings. There are multiple solutions and I've noticed that appSettings can be in a .config file in one project but which are somehow read in another project, sometimes in a separate solutions. What I'm trying to figu...
I work at a game company that has a Core Library with a bunch of ultities, extensions and systems that we typically import large chunks of into projects. Recently we have been trying to improve our process of improving our library. Essentially we gave devs freedom to write tickets themselves that they thought were impo...
In an RPC (Remote Procedure Call) design, an interaction across the network is hidden behind a synchronous API that makes the network interaction look (to the rest of the local program) like "just another local function call". The function-call sends its arguments (in some form) to the remote machine, waits for the co...
I am trying to engineer a library for the Genetic Algorithm optimization method. The main class for the GA is quite general. Here is what I have for it struct GAOptions{ size_t max_ga_steps; double weight;// -1 gives the maximum while +1 gives the minimum double cxpb; double mutpb; }; templ...
We have multiple publishers, that publish the data somewhere. For example, we have ElasticSearch publisher, AWS S3 publisher, or file publisher. Now the interface looks like this interface Publisher<T>{ void publish(T data); } now ElasticSearch or AWS S3 publisher does not require another parameters, it can get all ...
I'm working on a large C application that I've divided into sub-libraries (e.g. networking, message handling, message building, etc.) I've converged onto a pattern where functions are only allowed to return error codes, and all data must be returned via supplied pointers. This pattern has worked well because it is very...
I am writing a control app for a 6-DOF robot. This app can send scripts to the robot, which in turn executes these and thus moves around. In the app a robotprogram can be created by adding 3D coordinates called a point(class). This robotprogram is simply a Model with a List which contains all points. Also a few functio...
Having worked in complex solutions that had Unit Tests and Integration Test in the CI/CD pipeline, I recall having a tough time with tests that failed randomly (either due to random values being injected or because of the async nature of the process being tested - that from time to time resulted in some weird racing co...
In our company we have a requirement where we would like to store hundred thousands incoming records per seconds. we currently a pub-sub model for processing many records(100/sec) from many system(~1000) for listening to incoming events. now the problem is storing these records as fast as they come,(i.e. with minimum d...
Currently working on a project where the user will create a JSON file that's then read into the system. The fields of one object can be referred to in another object for relevant operations. Something like this: { employees: [ { name: "Mark", department: "Accounting", joi...
I am somehow stuck with my thoughts about an SLA definition, which I plan to determine for a REST-API running on a public cloud. Imagine having a REST-API service running on Azure which has a database as a dependency. To calculate the SLA for the infrastructure part, I would use the following calculation, regarding tha...
I assume the following is/reduces to a known problem, but I haven't been able to find it. I have a sequence of recipes with associated costs. Each recipe converts a set of resources to another set of resources. I.e. () -> (1A) cost 1 (2A) -> (1B, 1C) cost 2 (4A) -> (3B, 1C) cost 2 (1A, 1B) -> (1C) cost 1 I now want t...
I often get the argument that, if only a single team is working on the UI development, then the UI should not be developed as a set of Micro Frontends, with each one representing a subdomain. I would agree with the higher maintenance argument of such an architecture, but if one considered each Micro Frontend as an elem...
I have some doubts about RBAC which I cannot wrap my head around. So I would like to hear what you guys think. Though I understand the concept of RBAC, I cannot figure out how to apply that to my specific use case: I have a system that a company uses to audit its Franchises. So the components involved are: The actual ...
I have a micro-service based system running in kubernetes bare-metal. The key aspects are: download data from a datasource nightly and add to a database get any new data from the database, run a ML algorithm to get predictions for new data points I'm doing this using cronjobs at the moment, e.g. Cronjob 1 - python c...
Currently there's an aggregate root "Party" which for now only can be an insurance policy holder. A party can have multiple addresses, communication addresses (telephone, mail, ..), contact persons. A policy holder can also have multiple insurance policies, this is a different aggregate root. However new "personas" wil...
I'm in a situation that is the following: Company is an aggregate root and contains a list of contacts (name, phone, ..). On another aggregate root "Contract" you are able to add something called "Participants". A participant could be a company or a contact from a company. As far as I know, DDD doesn't allow to hold a ...
I have producers that take data A, produce data B and send it public interface Producer<T>{ void produce(T data); void flush(); } public class DataBaseProducer implements Producer<String>{ List<String> producedData = new ArrayList<>(); // create data public void pro...
Let's say we have an entity Customer which can have multiple email addresses. We create a ValueObject "EmailAddress", upon creation it checks if the address is valid. Is this concept valid and does it make sense? public class Customer : IAggregateRoot { public List<EmailAddress> EmailAddresses = new(); } If so, ca...
So a lot of the web says not to use public nested types unless you need the member visibility semantics (including this msdn article, even though that article hasn't been touched since 2008). For the most part, I agree with the line of logic. However, I am writing code right now that's performing deserialization of com...
is it possible to view behind the scenes of an exe file once its executed? to find the answers of a test questions? For example if someone clicks on F12 on a website the code is viewable to the user, is this also applicable to an exe file? Thank you.
Dave Thomas, the author of the Don't Repeat Yourself principle said: DRY says that every piece of system knowledge should have one authoritative, unambiguous representation. Every piece of knowledge in the development of something should have a single representation. A system's knowledge is far broader than just its ...
Model View Controller (MVC) is focussed on UI based applications. In MVC the model notifies the UI (view) when its values change and the view then decides what and if to update. I can understand this for desktop, mobile and single page web applications where there is a persistent UI. But why do some popular backend web...
We are currently in the early phases of developing several applications that differ significantly in their functionality. As part of building these applications, we have also developed a few generic BCs. Ideally these BCs should be reusable in order to minimize duplication and remove cross cutting conerns, and further ...
I've been reading about DDD a lot lately and something I can't find too much about is the following scenario: Let's say we have a Customer aggregate root and a Contract aggregate root. The reason they are both aggregate roots could be that contract could be accessed directly. A contract expects a Customer in the Create...
I am working on a relatively large project that could include +1000 iot devices, in this case probably a Raspberry Pi. So far I only experimented with ~ 20 - 30 devices but the concept should be the same. Currently thinking a lot about automatic Software Updates / Deployments on the device, when it's in the field (don'...
I was assigned a code review to one of my colleagues. I posed the following, which I wanted to share here in order to hear whether I am right or wrong. Consider the following code snippet: public void DoSomethingWithList() { var list = AnotherClass.GetList(); var itemsToRemove = list.Where(...); list.Remove(it...
Here is the pattern that I thought about for a resource accepting a single asynchronous HTTP request at a time (i.e. a request which has not yet been fulfilled when the response is sent): Create a single process: POST /resource → 202 {"monitor": "/process"} POST /resource → 409 "A request has already been accepted, re...
I have an Angular componente with two childs that requieres to share some data extracted from a http request. A service perform all the http request, and the parent component gets that data and manipulate it before it's shared to the child components. Is it ok to perfom data manipulation (maps to modify the structure o...
Given is the following dependency graph of a system with two subsystems. Calculate the CD (Component Dependency) of all components and also calculate the CCD and the ACD. See CDD here https://structure101.com/2014/03/10/why-cyclic-dependencies-explode-complexity/ This is my calculation: CCD = 5 + 2 + 2 + 2 + 8 + 1 + 1...
At my company we needed access to some variable to call a method on it, this variable is hidden about 6 layers down of different libraries code and each time it is behind a private variables (that this is so is a definite oversight, the method needed provides vital information pertaining to an exception that has occurr...