jeudi 19 avril 2018

How to make independent module with delayed callback information in Java project?

Im writing a project in Java with Spring boot. Im trying to write independent module (maven module) which sends data to verification.

Process looks like:

  1. Post data to REST API, get verification ID.

  2. Ask REST API (using ID) after some time about verification status or make REST endpoint and automatically get informed by external API when verification is done.

So in my independent module I got REST endpoint which gets data from fronted and sends it to external API. Then I retrieve assigned ID (which needs to be added to User Entity) and I don't know how to pass it to Main project module. My independent module does not know that Main module exist. Also I don't know how to pass verification status when my independent module will be informed by external API.

Is my idea a good approach at all ? Or maybe I should place REST endpoints in Main module and treat my independent module as service (through interface) which only sens data and retrieve ID? But then REST endpoint which expect information from external API also must be in Main module and I won't feel that this is separated functionality.

Thanks for any architecture advices.

wordpress design pattern name

Wordpress have a very nifty feature to add custom types: the field post_type in wp_posts. to create a new post type, plugin auothor needs to come up with a new value to put in the field and more tables that links to the wm_post table.

this feature repeats itself in many other cms systems.

My question is: is there a name for this design pattern?

Is this cyclic dependency

class foo{
Bar b;
}

class bar{
Class clazz = foo.class;
}

Does the above snippet show cyclic dependency. Class foo has a reference of bar class object. Class bar has reference to foo class itself.

Validation pattern of javascript

my validation is only input 0-9 and x,X

do not input 'space' or 'negative' numbers.

what type of pattern use??

/[^\dxX]/gi it not work on -1 , -2 ,etc

How to solve circular dependency in Scala?

I faced a problem with circular dependency in my Scala app. To give you more context, I have the structure below:

trait BTService extends CService with PMService

trait PMService extends CService

trait CService

In BTService I need some functionality from CService and in PMService also. I can see that there is a redundant dependency here (CService) but how can I avoid it?

Code design with Java Generics

Consider the following code:

interface A<T> {
  boolean someMethod(T obj);
}

class B<T> {
   T obj;
}

class C<T> {
  B<T>[] bObjs;

  public someMethod(A<T> aParam) { 
    //do some stuff
    if(bObjs!=null && aParam!=null) {  
       for(B<T> bObj: bObjs) {
         if(aParam.someMethod(bObj.obj) {
           //doSmth
         }
       }  
      //do smth
    }
    //do smth
  }

Problem: use of bObjs and aParam is optional, but it force users of class C to use the type parameter, even when not needed. Is there a way of designing the problem so that this is unnecessary? If I use a wildcard generic such as B<?>[] bObjs and A<?> aParamthen I can't use the method aParam.someMethod(bObj.obj). Is there any way of type checking/type casting to allow use of this method without requiring type parameters? The actual code is obviously more complex, and involves a lot of logic where aParam is used if present - the use of bObjs is pretty much limited to use of a single method involving aParam.

Thanks a lot!

Complex object inside another one

I have the following class

class A {
private:
   B b;
public:
   A();
}

class B {
public:
   void foo();
   void bar();
   void foz();
   ........
}

B has a lot of methods. Sometimes is needed for a "customer" of class A to use method of class B. I could return a reference of B, but in this case I should return a const reference because returning a non-const reference of a private object is not good programming. If the reference is const, foo, bar and so on can't be called because they aren't const. So the only "clean" way seems to recreate the same interfaces in A using delegation to B. But this approach is not really good because I should recreate all the interfaces in A. As alternative I could set B as public in A, but it seems "strange" to me. What should I do in this case?