New answers tagged

-1

That will very much depend on the size of the application and at what abstraction level the architect is working. If the application is a trivial application (like a school assignment) solving a well known problem with a well know pattern, most probably its architect will know the design pattern and be able to describe it like that. In larger systems, this ...


2

The time for solving only shows how experienced you already are in combination with how many similar problems you have already solved. And even then its not significant. Even programmers with a similar knowledge background, which have solved this kind of problem approximately equal often, will take different amount of times to solve this problem, because ...


4

Am I taking a long time to solve these problems? It's impossible for us to say without knowing your background better. But mostly it doesn't matter. When you're learning, things are going to take longer. That's okay. Am I going around and around with something that could have been solved in a much simpler way? Almost certainly. But mostly it doesn't ...


0

From the backend side, if you can give up some of the requirements there is a simple solution using JSON column in your table to store dynamic fields. In this case, you would have a map in your Project entity, and using Hibernate Types you can map them to JSON data automatically. This solution is enough to store, retrieve and filter by dynamic fields and ...


7

A common misconception among developers is that you can describe an application, or build an application, entirely by bolting together design patterns. Writing software is not a matter of choosing design patterns, arranging them properly, and then shipping a product. Software development has not become quite that modularized. If developers cannot build ...


3

You could use a custom interface with a single method (Single Abstract Method, SAM) and annotate it with @FunctionalInterface such that is usable as a lambda function, but has semantic meaning (by naming the interface and method). For example: @FunctionalInterface public interface UserRequirement { boolean checkRequirement(); } Some examples are here: ...


2

A couple of things to add to the existing answers. Caleth's comment is correct that classes do not 'subclass' interfaces. They 'implement' them. The distinction is that interfaces declare what methods a class must have on it. As long as your interfaces don't have conflicting ideas about what the same method signature means, you can implement as many as ...


7

That's very common, for example in java.util (in puml format) @startuml title Classes - Class Diagram interface Collection interface List extends Collection class AbstractCollection implements Collection class AbstractList extends AbstractCollection implements List @enduml


2

There's nothing wrong with it. Interface B is an extension of A, typically meaning that it requires a few additional methods to be implemented. If class BBase extends ABase (and you're sure that this is a good design decision, as nowadays we often prefer composition over inheritance), then if BBase matches the semantics of interface B and technnically ...


1

Efferent and Afferent coupling can be explained in simplified terms and visualized as follows: Efferent couplings count the number of things your component can be Effected by. Afferent couplings count the number of things your component can Affect. Dependency Injection has no direct relation to this concept of counting and evaluating dependencies; rather, ...


0

Order in the database doesn't matter. If an order is important it should be a column value. Even Kafka doesn't guarantee order beyond a single partition/key, so you really want an actual order column in those messages as well if order is important.


2

You ask "is it considered bad practice", and the answer is Yes. But not so much because of using KDoc/Javadoc syntax in an inappropriate place, but because of the level of commenting. If you feel compelled to comment your code inside some method, think about rewriting it to achieve better readability. In your example fun saveUser(user: User) { ...


2

It's just not useful to do that. The purpose of KDoc or JavaDoc is to run a tool to generate HTML documentation for how to use your code. They way the tool works is it scans for the specially formatted comments in specific locations (i.e. method declarations and class declarations). Depending on the tool used to scan for those comments you have two ...


2

They are different things. (efferent) Coupling refers to classes your code won't compile without. Dependency Injection is a way of passing in references to a class. So class Dog { List<Leg> Legs {get;set;} } Dog is coupled to Leg class Dog { Dog(LegBuilder lb) { this.LegBuilder = lb } List<Leg> Legs {get;set;} } new Dog(...


-1

Actually, JIT compilation has one major advantage compared to ahead-of-time (AOT) compilation. That is that the JIT compiler is able to optimize the machine code based on what the code is actually doing, not just what it could do. A good example is a virtual function call (method call in Java). When you write (C++) pBase->SomeVirtualFunction(); it may ...


5

Yes and No, You should have a client and model library published as part of the API project. Consumers of the api can use this library. So they will be deserialising to the same dtos or entities that you serialised If no library is available in the required language then the consumer will need to make one, and will hence need to make classes to deserialise ...


1

Maybe research we recently did, could also give some ideas on how Java could be faster than C++ (in some cases). The article can be found here: https://www.researchgate.net/publication/352705416_Improving_productivity_in_large_scale_testing_at_the_compiler_level_by_changing_the_intermediate_language_from_C_to_Java In this research project, we extended a ...


0

Now I'll note that this question is 10 years old, but: Use TypeScript (Also, VSCode) Easily and automatically refactor your methods and classes VSCode will do this. View instantly all the places where a method is invoked, or a constant is used (Open Call Hierarchy/Show References) Not a feature I use, but VSCode does this, and VSCode tends to behave ...


1

From your post it is not clear whether team name is the name of a team member or of a team role. If team name refers to a team role which might change on the request of the user, but not too frequently you could use an array of strings and store the array in a property. The next step would be to decide how to maintain the property file. You can change it ...


3

The project I'm working on has a code dependency on a TeamNames enum. So you have data that relates to each Team. That says to me that Team is a data Entity that you care about and, since a Team can probably exist in its own right, that means it should have its own table. The problem with this is that the project needs to be recompiled and redeployed on ...


0

Without doubt an enum is a closed value domain, and also a bottle neck on maintenance, like rebuilds and vcs merge conflicts and so on. An interface for team name typed constants. For different groups could define a child interface (Responsibility principle). Packing this value domain in a type is good practice. So there could be a class Team (?). Database....


11

Creating a single-column table in a DB just for team names would be overkill IMO. Create a proper Teams table then. With a key and Name and maybe some other properties that a team may have. This can be shown to the user as a select box. The user will see the name, the application will use the key for all its operations.


1

One additional thought: If you want to use your array of ingredients at multiple places, the classical arrCopy = arrOriginal does not COPY the array (at least in most coding languages) but just copies the reference to the array. As a result all changes on that array will be reflected also on all of those "copies". As a result, if such an array is ...


6

What your teacher is promoting is the "Builder Pattern" (or "Fluent Interface") wherein many methods can be called on an object in one statement: Recipe breakfast = new Recipe(); breakfast .addIngredient( "Bacon" ) .addIngredient( "Eggs" ) .addIngredient( "Mushrooms" ) ; The code using the ...


1

As a PHP developer I work with MVC frameworks. there we have Views - mostly to keep graphical design Models - wrapper around database tables Controllers - Classes where every function is called from a route and returns a http response, like view or redirect or error (404) Brokers - classes to get all the calculation and logic. It is like a black box that ...


2

Usually, it is a best practice to write constructors so that they should not have any side effects and external interactions. Just initialize the members of the object using only the parameters passed to them and do all of the complex operations in a separate function once the object was safely constructed. Or even better, let the only way for constructing ...


2

Injecting a class isn't really a violation of the Single Responsibility Principle. The new logic is encapsulated in your Operation class, that's it's responsibility. Calling a dependency doesn't really change what this class responsibile for. Something like the below isn't really changing the responsibilities of your DAO class. (forgive the C# syntax) ...


1

Others have commented on this - I'll state it bluntly. Don't lock whole tables. Web Applications are, by definition, multi-user, multi-threaded Beasts and each of those Users and each of those Threads will want to work with many rows in many tables all at "the same time". Think of cars travelling on a motorway. Closing a single lane slows things ...


0

Forget about everyone trying to help you build strings. What you are doing is voluntarily creating a HUGE sql injection target. Hackers will love you. You are giving them everything they need to break into your database, extract your data, or change your data.


2

Since you've already got a working solution, it's best to leverage what you've already built. You have a couple of approaches you can take: Azure Blob trigger invokes an Azure Function, and whole application is in the azure function Since your function is in Java, you will have slow start up times and that can add up in costs Azure Blob trigger invokes ...


0

You can always go with the AWS stack. Use S3/Glacier for uploading/storing the CSV (Glacier will be slow compared to S3 but it is cheaper than S3.) And for processing csv files, can always use lambda functions. (Costing of lambda function is based upon the, lambda invocation done)


10

Dependency Inversion does not remove the need for if-else or switch statements. If these statements get removed, it is a side effect of using dependency inversion, not the goal. There are two main benefits of DI. First, a class does not need to know how to initialize its own dependencies. This prevents a class from also needing to know the dependencies of ...


0

The problem What is the difference between a param object with an optional field which has a "field not set" value, and a method with explicit parameters for which null is a valid value to represent "optional parameter not set", and why is one acceptable and the other not? Let's say you have an UpdatePerson use case. Person has many ...


0

Let me start by describing two problems with Java: No distinction between nullable and non-nullable types. No support for parameters defaults Non-Nullable Types Many languages (including Java) make no distinction between types/variables that can accept a null value and ones that can't (except for primitive types like int - which can't have a value of null)....


0

No matter how you structure this, a race condition between processes will exist. The best thing you can do is attempt the INSERT, and if it fails, query again. First, you will need a unique constraint on the table to eliminate duplicate entries for each company. The C# code will need to query for that region, and attempt an insert if the region was not found ...


0

Adding instance fields adds to both the instance object sizes as well as the size of the (internal) representation of the class to which field was added — so, due to the former (the object size increase) adding an instance field scale as follows: the more instance objects, the more memory consumed.  Due to the latter (increase in metadata to represent the ...


2

Neither option is memory consuming. As a matter of fact, is reduces memory consumption and is the basis of the flightweight design pattern which sole purpose is to save memory while creating a lot of objects that share common data. I read your comment to @martin-mmat 's answer and you should add that clarification to the question since the A,A1,B,B1 names ...


1

Technically there is no issue with either of your solutions. Memory use is negligible. They do raise the question what you are trying to achieve and whether using an enum as a means to tell what type you are dealing with makes sense. Why do you think inheritance will be helpful when you are defeating the purpose of polymorphism? The interesting questions can ...


Top 50 recent answers are included