Spring DI with different styles

Spring as a dependency injection (DI) framework allows us to define our application components' dependency tree in three different ways: XML Annotation Java Config I've written a simple app, bookstore, with the three styles and they're available in the following repository. You can take a look and see how each style would look like. It also has a version that uses no Spring beans for comparison. https://github.com/ryu1kn/spring--working-with-beans Different styles have different pros/cons. Spring lets you mix the styles; so you can change it as you go. Here is my observations on each style. XML-based configuration Pros Weak/loose coupling with Spring framework in your app code. Good for keeping the option of removing Spring later Class dependency information is centralised. Fine-grained control on the dependency definition. Changing only the dependency information doesn't require the recompilation of your app code. Cons Unless you have a good IDE ...

Clojure Way

  • Do I have to use partial to do currying?

  • Do I have to do an explicit null check? e.g. html-node below can be null.

    (-> html-node (.getTextNode) (.getLiteral))
    
    • Seems so.

      (if html-node (-> html-node (.getTextNode) (.getLiteral)) "")
      
      ; or
      
      (#(if % (-> % (.getTextNode) (.getLiteral)) "") html-node)
      

      cf. in Scala:

      htmlNode.map(_.getTextNode.getLiteral).getOrElse("")
      
  • Can I compose a function from a Java object method with only its method name?

Comments

  1. Understanding function composition, currying, and Java method interoperability is important when working with functional programming concepts across different languages. The examples demonstrate how developers can handle nullable objects, compose functions using lambdas, and adapt Java methods for use in Clojure code, highlighting the value of understanding both language syntax and programming paradigms.

    These concepts are particularly useful for developers building applications that combine Java libraries with modern frameworks. A Java Full Stack Developer Course can help learners strengthen their Java programming knowledge and understand how backend components integrate with frontend applications.

    ReplyDelete
  2. For developers interested in building complete web applications using Java-based APIs and Angular, the JAX-RS Angular Course offers a relevant learning direction. Developing a solid understanding of Java methods, application architecture, and framework integration can make it easier to work with different programming approaches in real-world projects.

    ReplyDelete

Post a Comment

Popular posts from this blog

Use Blogger API from its Java client

Spring DI with different styles

Leverage shell commands to quickly edit text on Visual Studio Code