New answers tagged

0

Very good question! In general, as we can see from other programming languages, the intention of overriding a class member is expressed via a keyword. This is logical, because keywords are intended to be processed by the compiler, and their effect is manifested only during compilation. At runtime, the program has the keyword effect already baked in. This ...


2

Well, this is like asking what Gmail offers that Outlook.com does not. It's not technical No, really, I do believe that there is no technical reason behind this. What I am suspecting is that you are confusing the meaning of simplicity, although I am not certain about this. Since the creators of java decided that java collection streams are worthy of ...


3

Because it's the same URI, can I do that? Because the method is POST: yes, you can. Consider the example of the world wide web; GET fetches a rich HTML document, with lots of interesting links, and images, and scripts. POST, on the other hand, just delivers a bunch of encoded key value pairs. And it all works just fine.


6

we already had well-established mechanisms for manipulating collections in several other languages [...]. Since the creators of java decided that java collection streams are worthy of including in Java 8, they must think that java collection streams offer something which the (arguably simpler) pre-existing mechanisms do not." I think you're starting from a ...


0

You should call the third party in your Service layer. The reason being, the Service layer is typically used for all aggregations and related logic and from your use case you can call to third party API and perform subsequent transformation from their format to yours in the Service layer.


0

In Swift or Objective-C, you mark the method as @testable. The compiler knows when it compiles unit tests (because the end product is not an application or library but a "unit test" executable), and in that case allows calling private methods marked as @testable as if they were public. The advantage of this system is that your methods stay as private as you ...


2

I feel writing Services and ServicesImpl may not be necessary and I only need ServicesImpl because the content in Services and ServiceImpl will be copied over. The main reason to have a CardService interface and a CardServiceImpl implementation class would be to be able to easily swap out the implementation that gets used, for example for testing purposes. ...


1

This section from the book Clean Code, in Chapter 10 Classes > Class Organization > Encapsulation kinda implies that testing on private method is a pseudo-proposition. We like to keep our variables and utility functions private, but we're not fanatic about it. Sometimes we need to make a variable or utility functions protected so that it can be accessed ...


2

What I would do in such a scenario is create a separate project containing interface tests for version X. Once version X has been released, this test project should become effectively read-only. When you are creating version X+1 that should be backward compatible with X, re-run the interface tests of version X in such a way that the project actually picks ...


0

this is more like a long comment than an answer. I would suggest both of them are usable depending on your exact use case. Here are some of the considerations that can help with overall design: How will the user enter new data to your database ? How much constraint would like to apply during this phase ? For example would you like to let a user to enter "...


2

Expanding on Greg Burghardt amazing answer with a visual aid (and loosely using College Football as an example): public class Association { List<Conference> conferences; } public class Conference { List<Team> teams; List<Season> pastSeasons; Season currentSeason; } public class Season { List<Match> matches; ...


1

What you are doing, is trying to describe the "domain" sort-of independently first. Trying to figure out what contains what, what has what data elements inside, etc. You are wondering whether this model is "good" according to some metric, I guess. Then you mention as an "edit", as an afterthought what this will be used for. Modeling goes exactly the ...


2

You can't get sequential ID's across multiple threads without some form of synchronization. But if this requirement is optional, you can have a separate counter in each thread and combine it with a thread ID from a global counter. E.g. 64 bit for the thread ID combined with a 64 bit thread-specific counter into a 128 bit integer which is guaranteed to be ...


5

It's unclear why the standard answer, GUIDs, is inappropriate for your case. If the standard library generator is too slow for you, there are alternatives touted as being faster. If GUIDs are too slow for you, then you need to say what performance is required and why you can't just throw more CPUs at the problem. Secondly, you state no locking/blocking. ...


0

I don't know how much adopted is, but it's pretty sure that every B2B SaaS platform should deal with that kind of abstraction. When you build software that will be used from a single enterprise, you' ll have room to analyze and understand its domain and its behaviours, but when you build software for infinite, unknown enterprises, you have to find the ...


6

It feels like a good number of things are missing, to be honest. A Team has many Players. A Match is played between two Teams. A Season is composed of many Matches. A Season is managed by a SportsAssociation (think: National Basketball League [USA], FIFA, etc...) A SportsAssociation compiles a Team's SeasonRecord A SeasonRecord references a Team and a list ...


0

Are there any rules or principles to determine if the UML a good design before coding? Yes. Show it to a fellow programmer and ask if they understand what the UML is even trying to say. I am not sure if the abstract class can inherit another abstract class. Yes. So long as eventually you get to a concrete class. Too much of this will give you the yo-yo ...


0

What you are looking for is called Fluent interface, and it is not restricted to a "Builder". If ObjectNode would be class under your control, you could simply give it methods transform1, transform2 with the required signatures. Since it is a third-party class outside of your control, and Java does not support C#-like extension methods, your best bet is ...


2

No one got to the root of the problem. In spring-web, this is fine. The problem is that Spring Rest uses it, too. The purpose of the two are very different. When spring-web is doing it's thing to serve up my paths, that's great! I'll use the ControllerAdvice and what-not to handle those exceptions properly before sending a response to my user. However, ...


1

Judging from your example I'm not sure what properties of furniture are behaviors and what are implementations. Still, I'm not a fan of the 1st approach as it might be a case of premature abstraction. Consider the case when chairs or sofas have soft casing (I'm not sure whether this is the right word since I'm not a native speaker) in places where your sit, ...


1

That seems to be an interesting challenge indeed. As @DocBrown and you mentioned, make sure to have tests before changing the code. I may be late to the party, but I have a technique for you to set these tests quite rapidly. It's called "Approval Testing" (it has other names like "Golden Master" or "Characterization Tests"). The recipe is: Execute the ...


1

It all depends on your context and goals and how you see prototyping in your development approach. Basically, yes, it is ok to have a demo prototype with a very light fake or mock database instead of a real one: Iterating though all the "records" is then easy to develop. But of course, it is not very performant. Just make sure that all stakeholders ...


0

First let me say that there is absolutely nothing stopping you in Java to have checked exceptions work with Lambda's. The current implementation of Stream, Optional and some default methods on the collection classes however were created without allowing for checked exceptions. It is however perfectly possible to have a Function class that allows you to ...


1

I've will have business logic within my core POJO definition. I don't think that's a good idea because soon, I will start trying to bring in dependency injection of other member instances to help and perform the execution. You have really hit on the main problem with intermingling data transfer objects and business classes (also called domain models). Your ...


-2

There are.. ways: Most IoC containers are smart enough to allow wiring dependencies manually, in case of Spring looks like this:   public ClassA extends BaseClass { private String classA; @Autowired private SomeInterface interface; public void wireme(AutowireCapableBeanFactory beanFactory) { beanFactory.autowireBean(this); }...


Top 50 recent answers are included