mardi 25 août 2015

Circular Dependency in java- Design

How to prevent circular dependency, any design patterns??,otherwise it will cause stack overflow. I was asked to redesign this.

class A {
    static void method(){
        B.method(); 
    }
    public static void main(String args[]){
        method();
    }
}

class B {
    static void method(){
        A.method(); 
    }
}

Suitable Design Pattern for message mapping

There are two message types (A and B) (derived from same interface), A separate class contains the mapping logic. I need to map fields from message A to message B based on the logic in mapping class. What would be the suitable design pattern for this scenario ?

Domain Events Implementation

We are starting DDD, and we need to implement domain events (DEs). We are thinking about "developping our own system" vs "prototyping an exiting framework". We know some things about DEs. But we need to have some real-life feedbacks about what features should be expected from such a system, before taking a decision :

  • Should DEs be stored and duplicated in each domain from a centralized event-store, before being consumed (for maintenance and logging purposes) ?
  • Do domains pick up events from the centralized event-store (if none), or do we need some kind of orchestrator for dispatching DEs ?
  • If we use a relational database for storing domains data (we know we should ignore it when desiging business logic), does that relational database fit for DEs, or should we prototype a NoSql database ?
  • Do we need to implement some tools to ensure events are well propagated into target domains ?

I know there are many questions here, to summarize I would just ask :

Based on your experience, what are the key-features we can expect from a "theorical DEs system" ? Have you develop your own implementation, does-it make sense ? Does a service-bus meet our needs ?

EntityFramework for multi-form winforms desktop app

I am developing desktop app based on winforms and EF. At the moment I have some problems with EF and architecture:

  1. Syncronizing data. There are multiple forms and each form uses it's own instance of Database Context. When data is updated on one form I need manually update it on other forms. There are a lot of non-flexible callbacks and copy-paste that refresh data.
  2. There are some calculations that running on client side and update a lot of records. Sometime user need to save it and with EF it takes long time. So, it is also running in separate Context so that work with other entities is not blocked
  3. There are DataGridViews with Binding entities and there are annoying problems with DbSet.Local and DbSet.ToList(). When data in gridview is saved it is sometimes is not updated in other places.

I am looking for any best practices and flexible patterns that can be used there. Also, looking forward to hear from those who solved same problems.

Thanks

Add dynamically methods to an object

Could you help me to find a solution to my problem?

I have a class that represents an entity (I will call it "Entity") I would like to dynamically add methods to my Entity according to different criteria.

For example:

If $_POST['TYPE'] == 'typeA', I would like to add following methods:

  • method1()
  • method2()
  • method3()
  • method4()

If $_POST['MODE'] == 'modeA', I would like to add following methods:

  • method5()
  • method6()
  • method7()

The problem is that there will be a lot of possible methods and if I add all of them to my class, I'm affraid that my class becomes too big.

So what is the best solution to do that?

Should I add all possible methods to my class?

Should I use inheritance and create all possible kinds of objects (Type1Mode1Entity, Type1Mode2Entity, ...)?

Do you know a design pattern (decorator?) to do that?

Ben

Builder Pattern vs Java Beans thread-safe

Based on this example http://ift.tt/1MKpv12

What if I change the usage in the first example to http://ift.tt/1haKPAI

Isn't it the same as the builder from the thread-safe point of view?

akka patterns.ask implementation details

We have a use case where we have a set up like following Master type of Actor, Worker type of Actor. The master receives work request for an input and uses workers to orchestrate and generate result. There is a plan java class client.java. This creates a new instance of master and sends work to it. This client uses - Patterns.ask to get future pointer and later blocks on it until results are arrived.

Patterns.ask(master, initialMessage, t);
Await.result to get the message

The internal documentation of Patterns.ask says a temperory actor will get created. But, when I invoke and try to print the hashCode of the sender inside master, seemed same actor every time.

I have following concerns 1. How does concurrent invocations of Patterns.ask managed? Can it happen like a thread after calling ask gets a future pointer but wrong data is put in it? 2. How does it guarntee that Future pointers are filled with relevent responses only and not mixed up with responses from others? For ex: FutureX = future Expecting X message FutureY = future Expecting Y message Can it ever happen FutureX get Y and FutureY gets X?