instruction stringlengths 34 36.1k |
|---|
This is exactly my code, I'm just stripping out everything that isn't needed:
First of all, I met this issue a lot of times and something tells me that it's something to do with PHP itself and "data structure hinting"?.
I have 3 objects, all of them respect the following interface:
interface OutputExportData { function... |
I have an abstract class Dog and multiple subclasses (Beagle, Labrador, Bulldog...) extendig it. I have a DogHouse that can store a Dog.
My problem is that when I put for example a Beagle into a DogHouse like doghouse.addDog(beagle) and then take it out with doghouse.getDog(), this method gives me the beagle as a Dog, ... |
I am modeling a database that should be used as generic non-functional requisite for all services of the startup company, like persons, users, services and commercial data like coupons, signature packages, etc.
I am thinking about the gender model. In these modern days and with different laws across countries about sub... |
How can I unit test a codebase which contains classes that includes two or three methods. In general these methods are too long. The methods contain lots of tasks like filtering datasets and a couple of dml statements. Methods do not return anything.
I can define an input dataset, call the method and then check the ... |
I have a page where I list some products based on search data.
The products shown are not saved in local database, but are taken live using API (and this is how it has to stay).
When page loads, it first lists products from one provider (first API call).
After page finishes loading, then with Ajax the 2nd call to 2nd p... |
According to the GOF Design patterns' book, singleton pattern should be used when:
there must be exactly one instance of a class, and it must be
accessible to clients from a well-known access point
when the sole instance should be extensible by subclassing, and
clients should be able to use an extended instance ... |
I just read about all the 5 principles S,O,L,I,D and I like test it in little example if I understand them correct.
Which SOLID principles are hurt by this class diagram?
I think what is broken is Liskov Substitution Principle because if we take upper class Book and replace it with its lower class E-book then applicat... |
I am currently starting a new project with a 4-tier architecture design. The layers is set as follow.
+------------------+
+----------------+ Presentation |
| +------------------+
| ... |
I am looking for a design pattern for logging from within library code. Suppose I have a function in a library file that i expect will be used by multiple front-ends (lets assume a CLI and a web):
def foo(a,b):
log("Processing a")
p(a)
log("Processing b")
p(b)
Where would the foo get the "log" from? Should it:
H... |
What is the difference between using domain services and domain events? The thing I can see is that domain events allow you to further decouple your domain model and get away from using domain services. It seems the simple implementation would be to use a service and then eventually refactor to using domain events.
Add... |
I need to create properties that have values common to instances of a class. I'm unsure how to solve this problem, so I could use some help. (This is in C#, but isn't a language-specific question.)
I've been reading about single instances (not a singleton), static properties, and other patterns
This question is close, ... |
I am very new to writing Shell scripts and am trying to write a simple script to run Vagrant up then SSH into the box and run some commands. The echo Hi there will run but the read -p will never show. Am I doing this wrong or is there a work around of some sort?
vagrant ssh default << 'ENDSSH'
read -p "Enter your first... |
If this is basic question sorry , but anyway it is a question .
i am doing domain driven design , i know about RootAggreegate ,
Anemic model , Rich Model , Domain Services , and ...
but still when it come to adding or updating a model
i dont know what pattern it makes sense to use`?
should i retun void , or should... |
I was scrolling down on my YouTube Homepage and found that beside the filter marked Restricted Content, a point mentioned that the setting of this filter applies to this browser only. Here's the screenshot -
Now, I'm wondering what's the reason for that point. I think it seems to suggest that the filter's boolean valu... |
I just wanted some feedback on my definitions of these terms.
Abstraction - only showing relevant information and hiding implementation details. Interfaces and abstract classes are an examples of abstraction. Allows a user to use some form of functionality without knowing the inner workings. For example, the HashSet cl... |
Please allow me to ask my question using an example where we have a database with flight data and I want to make a web app where users can search, select, and book a flight.
I wrote some classes such as SelectedFlight, Ticket, and Passenger. For example, the SelectedFlight is supposed to represent the flight that the ... |
My previous question was just with class diagram and because of some comments I thought I try to find an example with a little piece of code for the diagram to see if principles correct understood?
class Rectangle {
private int width, height;
public void setHeight(int h) { height = h; }
public void setWidth(int... |
Is it preferable to define a single 'container event' like below:
trait UserStatus
case object Active extends UserStatus
case object Inactive extends UserStatus
case class UserStatusChanged(newStatus: UserStatus, userId: String, eventTime: Long)
or define to multiple events:
case class UserBecameActive(userId: String... |
Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a generic interface like:
public interface DataRetriever<T, R>{
R retrieveData(T criteria);
}
public class UserDataRetr... |
I have a camera based security system that uploads all its images via FTP to a folder in one of my hosting accounts. (FYI, I use it to watch my cats when I'm traveling). So I created a PHP file to simply display all the images along with their names and timestamp. Unfortunately the camera software creates separate fold... |
I am making a software to store all my company invoices (and then infer some statistics about it).
The idea is:
My company issues invoices to it's clients.
My company receive invoices from it's suppliers.
I made this class model to this problem.
But after looking at it again I realised that this may not be the best ... |
I am tasked to write an assembler in C, which lends itself sufficiently well in certain design-pattern scenarios, and in a parsing phase, after tokenization, I need to "fill-in" certain information that was previously ignored by tokenization.
I'll skip details, but the way I thought to solve this is by having a sole in... |
From what I gathered from learning Haskell, functional programming limits the amount of side effects, but in what ways? Hope someone can enlighten me on this one.
|
In developing/testing OSS libraries I can replicate a clean Linux fs using containers. However, if I want to test oss libs for MacOS end users, I seem to be in a bit of a quandary. Is there any way to create a clean fs on MacOS that I can test libraries with? Perhaps using chroot? Can someone explain exactly instead of... |
I'm looking at the builder pattern for helping setting up dependencies and parameters that may require complex logic for a class. But from the examples I've seen, the builder pattern does not seem very testable. Example I took from here:
public static class Builder {
private long accountNumber; //This is important... |
Now I have 2 objects which are "PROBLEM" and "SOLUTION", obviously "SOLUTION" is a proposed solution to a given "PROBLEM", my problem is that in my business I have the following relations:
a "PROBLEM" can refer to one or more "SOLUTION" (i.e. a "PROBLEM" that happened due to a "SOLUTION"),
"PROBLEM" can refer to one... |
I heard that you should avoid leading newlines when using printf. So that instead of printf("\nHello World!") you should use printf("Hello World!\n")
In this particular example above it does not make sense, since the output would be different, but consider this:
printf("Initializing");
init();
printf("\nProcessing");
p... |
Basically what this code does is to determine whether the user is allowed access to the page or not from list of pages as enum, each one has the role name as its name and the page name inside it.
The problem is that I don't think this is the best practice to write this code. why? basically if a new role is added I'd ha... |
Some of the Java libraries I have used so far seem to have a Factory for seemingly every other class in the library. Apache's FTP Server project, for example, provides a UserManagerFactory class which allows for configuring a prototypical instance of the UserManager class and creating copies of said instance - at least... |
I'm refactoring a settlements module in a large healthcare application. I'm trying to follow DDD.
Let me give you a short and simplified description of the refactored code:
A patient has an appointment during which they undergo several medical procedures. Every procedure has its price.
The patient can pay money to the... |
Let's say I want to design a distributed system whose only purpose is to assign each running node a unique identifier in some small range (Say, 5-100 nodes into a 10 bit identifier). When a node is added, it should get an unused identifier. We need to support more than 1024 nodes being added then removed, so of course ... |
Is renaming variables a type of refactoring, or is refactoring something different? In other words, what's the difference between renaming and refactoring? I thought they were the same thing.
"Code refactoring" mentions renaming only here:
Rename method or rename field – changing the name into a new one that better re... |
I have a ConstraintsResolver class which resolves a queue of Constraints. This is done when a ConstraintsResolver object calls meetConstraint() on a Constraint one.
Most of meetConstraint() implementations will return immediately, so I could just return a boolean, but there is at least one that will block, which means ... |
I'm trying to architect (breakdown) one application we have at my work in a few microservices. Before starting going down to the rabbit hole, I wanted to ask: when is a good idea to create another model+function instead of creating a microservice?
Creating a microservice involves more work than just a few other functio... |
My teammate has this class which contains a lot of Strings:
public class Config {
/**
* List of status
*/
public static final String IN = "bla*";
public static final String LUNCH = "bla*";
public static final String OUT = "*bla";
public static final String MEETING = "*bla";
public sta... |
My question is around how branch pushes work exactly; I have come across something that doesn't make logical sense to me and as such would like an explanation as to why I am experiencing this behaviour.
I have two branches: master and dashboard.
I am on (checked out) dashboard. I make some changes on it and (using the... |
Suppose we have a service that returns users in certain categories, e.g.
Listens to a certain artist.
Listens to a certain playlist.
Listens to a certain genre.
Is between ages X and Y.
Is located in geographic area Z.
Suppose an external CategoryService manages valid categories, and we use a CategoryServiceFixture f... |
I have a REST API that has been built on top (in front of) a legacy system, to allow 3rd parties of various platforms to interact with the system.
Most of the time, I can define a resource and create a GET and POST/PATCH etc. However, I have a couple of cases where the GET needs to be able to handle potentially a large... |
I realize that DDD advocates eventual consistency, thus allowing for a certain period of time in which the system might be inconsistent. Embracing eventual consistency, we can therefore model our aggregates in such a way that only 1 is updated per transaction.
However, my question is, what if the relationship between m... |
I am maintaining a public API and have to deprecate a method.
Is there a general rule on how many months/years/versions before the deletion I should deprecate a method?
|
I am making a websocket server that can communicate with clients.
This server is going to be on a private vLAN channel on a public place, AKA only the staff have access to the network which the server is on.
When this is the case, do i need to implement SSL or any other form of security, if the "hackers" cant get acces... |
I have a class named Change which should be abstract and have some basic methods.
I have classes Insert, Update and Delete that extends Change.
In the case of Insert, Update I just use extend and add no logic!
public class Insert extends Change {}
In the Delete class I have an extra method that doesn't exist in the Ch... |
I'm running into a design problem. My code is in C# but the concepts could apply to any OO language.
I'm designing a framework to run experiments, and these experiments have several variables which we will manipulate, and several variables that we will calculate after manipulation (like columns in an excel sheet). Each... |
I was refactoring an application to respect SOLID principles. When I was applying interface segregation I found the following case:
interface A
{
void methodA();
void methodA2();
}
interface B
{
void methodB();
void methodB2();
}
interface C : A, B
{
void methodC();
}
interface D
{
void m... |
Requirement
There is some (for arguments sake) “global” application state that I am interested in injecting into components.
Each candidate component should receive an immutable snapshot of the state as it existed at the time that its constructor was invoked (for absolute clarity, the state snapshot that is injected i... |
I have two classes, Bar and Baz. Both subclass the abstract class Foo which has a method doThing(). Bar implements a functional interface Now which contains method doThingNow() whereas Baz implements a functional interface Later which contains method doThingLater(). It's likely that I will have more classes down the li... |
I have a AR called User, which has among other entities one called City.
The way I assign a City to a User is:
$user->addCity($city);
The problem comes when a id is given at some Controller endpoint instead of a City entity, I can't relate them if it's not through an instance and I can't retrieve the entity intance wit... |
I have a branch (dashboard) which I am developing a new feature on.
To make the example easy to follow, I am developing two separate functions (function1() and function2()).
They work how I want them to, but I now want to attempt to merge function1() and function2() together to make new_function() because I think it wi... |
I face an issue if to use a decorator or facade pattern to accomplish my needs.
Imagine a client wants to play a video. He can use the interface
public interface IVideoPlayer
{
// Prepares everything to set up and plays the video
void Play();
}
The client should not be concerned with the preparation, so the i... |
My program needs to execute a sequence of steps from start to end. But based on different input the start point will vary, e.g, some will run from the first step to end, some will run from the 2nd step to the end, some will run from the 3rd to the end, etc.
I just need a simple design, currently I use fall-through swit... |
My team (yet) did not do much to work on technical debt and our code base includes huge amount of TODO code, unused code, 'could get better' code, @Ignore unitests and more.
I am about to start dealing with those issues, and as we work on production product and have many other things to do, i was thinking of this strat... |
I'm learning to program the Game Boy Advanced (an old Nintendo console.) I was reading one of the best tutorials about it and it said this about how branching can be done with arithmetic.
[To optimise your code] avoid branches. Things that redirect program flow (ifs, loops, switches) generally cost more than other ope... |
When writing web applications I place business logic in controllers. This has worked well for my small App Dev team- our applications run reliably, perform well, and the code is easy to maintain. See below for an explanation of my design.
Contrary to my architecture, the advice I find in programming forums usually ad... |
Is it wise to use kafka as the 'source of truth' for mission critical data?
The setup is:
kafka is the underlying source-of-truth for the data.
-querying is done on caches (I.e. Redis, ktables) hydrated from kafka
Kafka configured for durability (infinite topic retention, 3+ replication factor etc)
architecture follow... |
I currently use the following naming scheme for my unit test projects.. if I have a project "MyApp", I will have..
-- MyApp
-- MyApp.Tests
I see this is quite a common practice.
Now, the problem is, if I then have another project MyApp.Common. Now in solution explorer, my projects are sorted
-- MyApp
-- MyApp.Common
-... |
I have a server-side service (using ASP.NET Core) that should provide a REST API to various clients.
Behind the service, I use a SQL server for data storage.
The controller has the following route attribute:
[Route("api/[controller]")]
[ApiController]
public class CustomDataController : ControllerBase
{…}
There are da... |
I will use the reference tables for the first time so I have some questions about it.
Example Table
------------------------
id | description |
------------------------
1 | Some description1 |
2 | Some description2 |
3 | Some description3 |
------------------------
1) In order to increase code legibility I wa... |
I have a temporary report table which has a foreign key (source_id), e.g. report table:
| id | val1 | val2 | source_id |
| -- | ---- | ---- | --------- |
| 1 | 102 | 0.5 | 1 |
| 2 | 99 | 0.9 | 1 |
| 3 | 212 | 0.1 | 2 |
and example of source table:
| id | descr |
| -- | ------- |
|... |
What algorithm does a video player use to find the subtitles to show at any given time?
I'm building a video player that displays some notes on different times over a video. Each note has a starting time and an ending time, just like subtitles.
I'm having issues coming up with an algorithm to find the all the "notes" w... |
malloc and calloc have these signatures:
void* malloc( size_t size );
void* calloc( size_t num, size_t size );
They do basically the same thing. Both allocate a chunk of memory of the specified size and return a pointer to that chunk. The difference is that calloc initializes the whole memory to zeros. Actually, callo... |
Can anyone tell me which one is better approach between synchronization method and private final object in java and why ??
public class kclass {
private final Object myObject = new Object();
public synchronized void show() {
...
}
public void show1() {
synchronized(myObject) {
... |
Does anyone know a term for these kind of user interfaces? Some examples:
old BIOS menu of PCs
safeboot menu of windows
other old MSDOS applications running on fullscreen using "keyboard navigating menus" (like accounting softwares).
What is the technical term for such types of interfaces? This could be helpful whe... |
I am currently in a continuous software product development project on base of legacy Java code. The source code is very complicated, which is good and bad.
But I am surprised to see that in the core component most of the classes contain thousands of lines, not one thousand of lines but usually over 5000 lines, in only... |
I need to design an AST-like class hierarchy for the introspection of code (like the Java Element API used during annotation processing). But I'm unsure how to make it maintainable and easy to use.
My instinct is to model the language as closely as possible and take full advantage of the type system. In order to do th... |
I was recently looking through the CPython source code and noticed something rather intriguing:
/* Minimal main program -- everything is loaded from the library */
#include "Python.h"
#include "pycore_pylifecycle.h"
#ifdef MS_WINDOWS
int
wmain(int argc, wchar_t **argv)
{
return Py_Main(argc, argv);
}
#else
int
ma... |
Our team has different opinions about the practice of using self-defined exception for handling the business logic.
Someone says it is good as the exception comes meaningful and readable, and the opposition thinks it is redundant to define every possible exception and catching exceptions is performance hurting.
Would... |
What is a firmware design document (FDD) in terms of an embedded system?
I am working on developing an application that would be working on a customised board similar to the Xilinx Zynq Development Board(running on Arm Cortex A9 processor). I am using the SDK IDE provided by Xilinx which provides some in-built librari... |
Let's say I want to parse some JSON and I store the path in a Java constants class the path that I want to follow.
For example:
public static final List<String> path = Arrays.asList("a", "b", "c");
so that I can do this (pseudocodeish):
public boolean checkSomething() {
JsonThing json = ...
for (String pat... |
For example, suppose I have a toggle button listener, and it has some tasks to do according to the state of toggle:
style 1 : use many ternary operator:
tutorialModeToggle(isTutorialOn){
SoundUtility.play(isTutorialOn?"s1.mp3":"s2.mp3");
this.titleLabel.setString(isTutorialOn?"(Tutorial Mode)":"");
this.tut... |
To introduce some license levels (organization, computer, user), I need to pinpoint information that identifies the object (organization, computer, user) without user interaction.
To identify the user for a user based license, I have used the user name, domain (either AD domain, or computer name), and user security ID ... |
I want to program a simple budget application. In my application, the budget is divided into budget periods (months by default, but it can be bi-weekly or weekly periods). In each period there is a list of spending categories.
The user can perform different action on a category, like to record a spending, allocate bud... |
Coming from the world of C and C++, most build system have an install target, notably Makefiles (where it is recommended by GNU for example) or CMake. This target copies the runtime files (executables, libraries, ...) in the operating system (for example, in C:\Program Files\ on Windows).
This feels really hacky, since... |
I have multiple methods that could fail, let's say :
readFile()
parseFile()
compute()
Each of them could fail (e.g file not found, wrong file type, wrong data), should I put each of them in their own try/catch block or should I create one try/catch block then switch the error and log/display text depending on the err... |
I'm making contribution to an opensource project by one of the leading hypervisor providers and I have noticed that there is awfully lot of repetition.
Below is what I mean by it, imagine that they do this multiple times in the same class and then across other classes.
def get_some_stuff_type_A(self, name):
"""The... |
Assumption: Each product codebase is in a separate repo. If the product codebase was a mono repo, it would be a no brainer to just put them together.
Assumption: Integration tests in this context would include end-to-end UI-layer tests (e.g. Selenium) and end-to-end API-layer tests (e.g. GraphQL/Rest). Tests requires r... |
I'm currently building a new application and trying to apply some of the principles of Clean Architecture. One of my first roadblocks is implementing my own Identity system (to avoid being tightly coupled to the AspNetCore.Identity library.
One of my concerns is password hashing and generation. I'm looking at followin... |
I am currently working on a bare metal project with an arm processor using GCC arm compiler. If I call malloc, is the allocated memory tracked in the MMU? For some reason I had assumed an OS typically handled this but since the call to malloc compiles and I see it is defined in the libc/usr/include I am now thinking th... |
I have kafka consumer that get data from kafka and do some process if some circumstances meet and send it for another consumer to do it's job.
How can i build something like this?
One way I think about is consumer-1 get data from a topic-1 process it and send result to topic-2 for consumer-2 to consume. Is there any be... |
I asked this question already at stackoverflow together with a serialization related part and at codereview for the design part only. Since the design related part receives no answers or comments on stack exchange and was off-topic on codereview I'd like to ask about it here.
The problem: I have a complicated class hie... |
Suppose I have a loop (in Python syntax):
xml = "<x>...</x>"
for i in arr:
j = f(x) # some complex computation
obj = Class(i, j)
xml = obj.run(xml)
Does it make sense to use dependency injection for Class in this situation? If yes, what is the proper way to use DI in this context? Please provide an exampl... |
We have a hierarchical database at our institution that has exposed a SOAP endpoint as the only way to make CRUD operations against it. We are primarily a .NET Core shop. I'm trying to conceptualize how the architecture of an app that uses the WDSLs would look. The main use case is to display account info in a pleas... |
This is only an extract from a very long text, the one I'm not sure about. It's about a photo booth (an automata that makes a picture of you if you insert coin).
The automata has a camera that is recording once a coin is inserted. The customer has 2 minutes to freeze the video right after the coin was inserted, such th... |
I have made a small library/application that I intend to distribute. However I want to find out what versions of python can handle my script ? Given that there are many minor and micro versions and two major versions too, how do I go about doing this?
I thought about using docker to do this, but I am not sure if tha... |
Our team is attempting to "modernize" an old ASP.NET Web Forms application. One aspect we want to improve is its visual style as it looks very dated by today's standards. Additionally, its existing CSS stylesheet is an abomination and it would be easier to throw it out and start from scratch. Sadly, none of us are C... |
Assume we have a large enterprise-level application without any unit/functional tests. There was no test-driven development process during the development due to very tight deadlines (I know we should never promise any tight deadlines when we are not sure, but what's done is done!)
Now that all deadlines passed and thi... |
When using a call-back to show progress on a multi-phase task, I don't know how to calculate the progress per phase well. One of the phases is collecting data, which differs in size from run to run.
Putting global percentages into the calls all over the code needs changes as soon as a phase is added/removed, and it d... |
I need to build a REST/HTTP API that has user accounts that other sites can use.
It is my understanding that it is incorrect for the other sites(that use our API) to use a password field to allow users to log into our service. And this is mainly because the other site could log the user's password. So instead you have ... |
How exactly should gitlab-ci behave to version my project ?
A simple git flow on gitlab could be:
commit on master -> build, test and deploy to staging
tag on master -> build, test and deploy to production
But how do you deal with version ?
1- should the deploy version be based on the tag ? if yes do you update the p... |
I'm currently analyzing a problem in a old "distributed" system, that only occurs sporadically - as the system does not support other means of debugging help I have to rely on the logs (I did not design or develop that system).
Currently I do only the steps to trigger that error (of cause only sometimes, without any ob... |
We are developing some Python applications (mostly CLI) for use only internally in the company. Hundreds of machines on which the applications may run. Instead of installing the apps on each machine, we would like to use a shared network filesystems that they can all access as the deployment target. Some packages need ... |
Situation:
In our system there are a lot of certificates. Some of them are used to secure HTTPS endpoints. Many more of them are used as a means of authenticating our system to an external system (we integrate with over a dozen of other systems). Some others yet are used to authenticate external systems to our system.
... |
I really don't understand the SRP applied to a "real" project (really not so real but can help me to know your approach)
I find very difficult to divide and assign responsibility to my classes.
So I posted an example in pseudo code, and I hope someone can enlighten me.
I have a simple Windows form,
INPUT : an excel fi... |
For reasons, my search endpoint returns a maximum of 50 results.
I'm struggling with how best to tell the caller that their results were limited to 50.
The best I've come up with is returning some additional fields:
{
results: [
...
],
resultsTruncated: true,
resultsReturned: 50,
totalMatchi... |
Is it enough for methods to be distinguished just by argument name (not type) or is it better to name it more explicitly?
For example T Find<T>(int id) vs T FindById<T>(int id).
Is there any good reason to name it more explicitly (i.e. adding ById) vs keeping just argument name?
One reason I can think of is when signat... |
In C program I'm doing below stuff
int x = 4;
Let us assume integer has 2 bytes in this case.
So my question here is
the variable x will hold two bytes that mean 16 bits. So here how the value 4 will be stored in 16 bits ?
Till now my understanding is the value 4 will be converted to Hex so it results [0x0004] and th... |
I have this IdentityServer which handles authentication and authorization. It saves users, roles, claims, etc in its own database.
Then, I have a web app that needs to protect some resources to specific roles. This is, of course, handled by the IdentityServer.
Now, the question is, I need to associate some entities in ... |
I am creating server/client application. The server and client parts should be written in C language. However, for user interface I would like to use javafx. So, the question is it possible to combine javafx with C? If it is, then how do i do this in a proper way?
|
Is the Default Constructor of Super or Parent class Can be Inherited into Child class ?
|
What are your thoughts on mediator pattern being used from a client and across a web api?, this means:
Command definitions are shared between the client and api.
Web api exposes only one ExecuteCommand REST method, wich is wired up using mediator pattern to the command handlers.
Client app uses mediator pattern too, t... |
Suppose I am developing a RSS system (following DDD practises). Users have accounts. Accounts have feeds. Feeds have articles. Account, Feed and Article are my aggregate roots as well as ArticleAccountMeta (an aggregate that contains information whether an account has already read an article).
I decided to go without s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.