We changed our privacy policy. Read more.

Hot answers tagged

53

Field injection is a bit too "spooky action at a distance" for my taste. Consider the example you provided in your Google Groups post: public class VeracodeServiceImplTest { @Tested(fullyInitialized=true) VeracodeServiceImpl veracodeService; @Tested(fullyInitialized=true, availableDuringSetup=true) VeracodeRepositoryImpl veracodeRepository;...


33

The argument of less test initialization boiletplate is valid, but there are other concerns that must be taken into account. First of all, you have to answer a question: Do I want my class to be instantiable only with reflection? Using field injections means narrowing down compatibility of a class to dependency injection environments that instantiate ...


23

Field injection gets a definite "No" vote from me. Like Robert Harvey, it is a bit too automagic for my taste. I prefer explicit code over implicit, and tolerate indirection only as/when it provides clear benefits as it makes code harder to understand and reason about. Like Maciej Chałapuk, I don't like needing reflection or a DI/IoC framework to ...


10

Well, this seems a polemic discussion. The first thing that needs to be addressed is that Field injection is different from Setter injection. I already work with some people that thinks Field and Setter injection is the same thing. So, to be clear: Field injection: @Autowired private SomeService someService; Setter injection: @Autowired public void ...


9

Your primary difficulties I feel are that you have a mismatch between a very linear and custom workflow in an older application that do not coincide with the user interaction workflows that are common on the web. Web applications that interact with a server application that contain the business logic communicate in a Request/Response messaging style. The ...


8

It is a little unclear if you mean sharing the same J2EE container or physical server. Regardless, my suggested approach is the same but I don't know if I am suggesting option 2 (which I think I am) or a third option you had not considered. If you try and host lots of apps as one app it means you will suffer from far more from things like threading overhead ...


8

Remember, the original GoF book has the full title "Design Patterns. Elements of Reusable Object-Oriented Software.". And most of the GoF patterns have that purpose - build software which can be put into libraries and/or frameworks and reused in a wide range of use cases, in a black-box manner, mostly following the open-closed principle. So if one is not ...


8

Most frameworks already use a lot of known software design patterns. So you are using design patterns unknowingly. That said, I would strongly suggest you to try learning at least the most common ones. It's funny. In the other hand, in a framework, your classes "fall into place" within the design of the framework, but you have to code your business logic ...


7

The standard structure for a WAR file is: /META-INF Standard jar stuff like manifest.xml /WEB-INF web.xml /classes /com...etc. /lib Maven generates this for you using your src/main/java, resources, webapp and your dependencies (placing them in /lib) in the maven-webapp-plugin, but that's implementation. The important thing to realize is that ...


7

There are actually multiple ways to reduce the size of .jar files. If you really need to reduce the size of .jar file without dropping some content, I would recommend trying the following two automated tools. Compression Perhaps the easiest way is to use a different tool to create the .jar file than the standard jar distributed with the Java SDK. KZIP is ...


7

There seems to be a mismatch between what you mean by the word "logger" and what the Log4J framework means with "logger". Within the Log4J framework, a logger is a very lean class. It is not much more than a wrapper around the ThisIdentifier that you use and an container for functions that generate logging statements. All the heavy ...


6

It's probabbly an wrong assumption, first as common sense nested calls shouldn't have any (measurable) performance hit at all. After doing some research you'll find that the JVM can do some optimizations in your code "automagically": Adaptive Optimization And more importantly: Inline Expansion As you can see: In computing, inline expansion, or ...


5

You might save a bit of disk space with the god application approach, which btw is an anti-pattern. But you're gaining a maintenance nightmare, deployment nightmares, support nightmares, etc. etc. etc. I think you get the message. Rather than deploying just one part that changed and leaving the rest you now need to every time some tiny thing changes in a ...


5

The usual answer to "what is the right way?" or "is this the right way?" is..... it depends. All I can do is tell you the pros and cons to specific ideas. What follows is 100% my opinion. I don't know of any specific requirements or rules. I'm sure somebody will disagree with me. JSP's Let's work on whether to put JSP's in WEB-INF or not. Pros of ...


5

The short answer is that Java web developers, as a whole, seem to be happy with the tools/frameworks they currently have, and do not prefer the Rails way of working enough to make such an effort worthwhile. Feel free to start a project if you think it would help. The Java platform has many frameworks for doing web development, some provided by Sun/Oracle, ...


5

The easiest way to avoid dependencies on a framework is to not use a framework. Abstracting frameworks just doesn't work in practice. For example Microsoft tried creating an abstraction over their MVC Di framework and it caused way more problems than it solved. Abstractions add complexity, always. Therefore there has to be a benefit to that added complexity....


5

The first thing is to realize you don't have to understand the entire code base. The abstraction is there for a reason. Try to mostly trust it works as it claims unless proven otherwise. The second thing is to keep notes. I do this by writing my main question, something like, "Where do I make this change?", then indented under that I write the questions I ...


4

As a web developer, there are mainly three environments to consider practically: Production: The environment configured to host the final release version of a product targeting end users. It is optimized for security and performance. It is hosted on a live server. It requires alerted and urgent support. It is data-critical. Therefore, its data is backed up ...


4

My experience with US Government/Department of Defense IT is that: DEVELOPMENT/TEST is for developers and application developers. They build and test applications away from enterprise systems. When the applications are completed, they will be deployed to the IT environment into the PACKAGING server(s). From that point on, the applications are supported by ...


4

You say: The problem I'm currently facing is mixing a website frontend with a distributed backend written in differnet languages (there is some C++, Erlang and Haskell stuff to consider). Tasks need to be dispatched from the web frontend to the many backends asynchronously and reliably as well as also having certain tasks run regularly like a cron ...


4

There are various different definitions of what it means to be "object-oriented", but it turns out that all of those definitions are just approaching the problem from different angles and actually agree with each other. Alan Kay, the creator of the term "object-orientation" says: OOP to me means only messaging, local retention and protection and hiding ...


4

But are there any software quality advantages from one to the other? Programming is complex and so we try to do things that make it more manageable and maintainable. One tool we have for that is abstraction. If we can abstract the relevant details and hide the implementation of those details that gives us an advantage, because we can consider fewer rules ...


4

I don't think there's any recommended way to go. That said, as a developer, I would hate a company where the IDE choice is imposed. Developers are more productive and happy with their favourite tools. Also try not to be locked into an IDE. You could regret it in the future, imagine if next year some company delivers a new IDE with many killer-features, why ...


3

Dependency injection (whether done through the constructor or with a DI framework) is one way to implement the strategy pattern, but so is a factory method. In general, DI frameworks (like the one implemented by Spring) allow you to declare system-wide injection dependencies in a single location.


3

What's an API ? It is an interface by definition. Consider the software you're using as a blackbox. You're not supposed to know how things are done internally, nor are you supposed to want that, or you would just build things yourself. Besides, trying to extend an API class yourself may break the tool's behaviour (which, once again, you don't really know). ...


3

The JVM have this thing called JIT, which would optimize the application's code with various techniques. One of those is called "inline optimization". In this particular optimization, the JIT will automatically inline methods when needed, so, you might lost some processor cycles in this particular instant, even if it does, it's not sufficient to justify ...


3

I see this in the .NET world as well and I have so far identified a handful of reasons as to why this happens (I also do not prefer anemic data models). Old code. People didn't know better and it's too expensive to rewrite. Misinterpretation of the DRY principle. People want to use their objects as contracts and send them over the wire as XML/JSON and then ...


Only top voted, non community-wiki answers of a minimum length are eligible