How to find out "separation of anxiety" in java

In another question, someone told me to implement the following in my java program. But I am very new to Java, and I don’t know how to start converting my simple program into this structure:

Data Access Layer (read/write data)
Service Layer (isolated business logic)
Controller (Link between view and model)
Presentation (UI)
dependency injection. 
program to the interface:

Does this fall within the scope? Should I start Spring training and will this structure evolve naturally? Or can I implement the above technologies one by one without using a framework?

+3
source share
6 answers

You can implement them without a framework if you want, but you are giving up any advantages that the infrastructure offers you.

, , - ; . Spring, , .

, , Spring. SQL . , .

, .

, JDBC, JSP, JSTL ( ). , , .

Foo, , , :

package model;

/**
 * A model object that interesting from your problem point of view
 */
public class Foo
{
}

package persistence;

/**
 * CRUD operations for a Foo 
 */
public interface FooDao
{
    Foo find(Long id);
    List<Foo> find();
    void saveOrUpdate(Foo foo);
    void delete(Foo foo);
}


package service;

/**
 * Just a data service that wraps FooDao for now, but other use cases would 
 * mean other methods.  The service would also own the data connection and manage 
 * transactions.
 */
public interface FooService
{
    Foo find(Long id);
    List<Foo> find();
    void saveOrUpdate(Foo foo);
    void delete(Foo foo);
}

package view;

/**
 * A class that owns services, validates and binds input from UI, and handles routing 
 * to the next view once service is complete.
 */
public interface FooController
{
   ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response);    
}

, , . .

0

, Domain Driven Design. Java. , , , .

+1

:

  • - , . SQL, XML, . , , VO DTO DAO
  • . . .
  • - , / / .

    , / , , , - .
  • - . -, HTML Java Swing , . GUI . , , , , . , , .
  • Injection Dependency - . . . , , plug-and-play, , .

    Spring - . , , . Spring MVC framework, - .

. , , . Java.

+1

, - , .

, , , ( ), (, Hiberante, Spring, Guice ..). ( !), , , .

Spring , , . (.. Spring). , Spring MVC.

0

. , , . -, , "" - , . , , - , .
, Model-View-Controller pattern (MVC) - (SOA).
, Java. , Java-. , . , Spring Web MVC, , Spring Framework, -, MVC.

0

, calss .

Data Access Layer (read/write data) -> one class for presisting laoding
Service Layer (isolated business logic) -> one calss with bussiness logic
Controller (Link between view and model) -> in simple swing app this merges with UI
Presentation (UI) -> one class for one widnow
dependency injection -> not used in small apps 
program to the interface -> Your service class should use interface tah is used by other class instead of directly your serivce implementation:

, .

- ! , begginigs!

0

Source: https://habr.com/ru/post/1786905/


All Articles