mardi 1 août 2017

Using DDS Domain Objects in code

I have an architectural question related the Data Distribution Service (DDS). What are the downsides to using Objects imported from DDS directly inside your code for presentation to the user?

I'm working on a program that listens to a large amount of data from various sources and receives everything through DDS. What is the correct approach for handling the objects received via DDS? Or at least the pros and cons of each.

1) Use them directly?

2) Should I encapsulate and pass them through my code with accessors that wrap the fields of the DDS Object?

3) Convert them to an equivalent business object (including corresponding enumerations) and pass my new object.

The second two options will allow the DDS Domain Object to change with minimal code changes, but is the up-front work of converting all of them worth the time it will take me? There is also some extra processing overhead in new object creation.

In the instances where I will be using JavaFX to display information, the third option is required to use bindings. For those particular instances, however, the objects will just be updated as new domain objects come in instead of recreated so the overhead for object creation is mitigated. That is not the case of all of the DDS data.

MVC Application Loading Notifications

I am going to be purchasing an MVC theme from WrapBootstrap http://ift.tt/1i4NW7g for a personal project.

There are alot of things that I like about it design wise, but it has brought up a question about the best way to load notifications in the header (really any sort of dynamic data that needs to load into the common Layout view).

I know there are a great number of ways to do this, but I am at the point in my development experience where I am trying to break my bad design habits (hacking things together so they "just work"), and look for elegant solutions where I can.

The things that make the most sense so far is to either:

1) Create a global ActionFilter that will filter all requests and throw a "LayoutViewModel" into the ViewBag, and just use the ViewBag in the _Layout view.

  • I'd rather do something strongly typed, but I don't see a way.
  • This is nice because it is available, does not require my controllers to inherit any functionality from a base class that might be cludgy, or even know that it is happening.

2) Load the page and onLoad, just do an Ajax Calls to the server to load any dynamic data I need.

  • This may have some disadvantages if your layout needs to change based on the data. I dislike with things snap all over the page after loading.

Is there a design pattern or MVC feature that I may be missing top accomplish this?

I may in the future I may implement something liks SignalR(or a simple timed ajax call to look for updates) to get updated data/notifications, but for now I am just looking at the initial page load.

Thank you for any ideas that you may have.

Is there a design pattern or basic object-oriented principle that deals with this case of shared resources?

Let's say I have three classes, Solid, Face, and Edge that are defined as follows:

class Solid{
    public:
        // perform an action on a single edge.
        void addFillet(int edgeNum);
        // perform an action on a single face
        void addBore(int faceNum);
        // perform an action on all faces and edges
        void move(Pos newPosition);
    private:
        std::vector<Edge*> edges;
        std::vector<Face*> faces;
};

class Face{
    public:
        // will modify a subset of edges
        virtual void changeHeight(int newHeight) = 0;
    private:
        int myNum;
        std::vector<Edge> edges;
}

class Edge{
    public:
        virtual void changeLength(int newLength) = 0;
    private:
        int myNum;
        int length;
}

in this example, Solid manages a 'superset' of Edges. Each Face that Solid manages will have a 'sub-set' of Solid.edges. Further, any two Solid.faces may have a common Edge.

My question: are there any design patterns or general object-oriented principles for dealing with situations like this? How can I manage the relationship between Solid.edges and Face.edges? More specifically

how to find a specific word having random located newline

As I stated on the title. I'm try to find regex result on a specific word(like apple) having random newline(\r\n) special character.

Illustrate more detail... Let's find a word 'apple' on the text file. but We don't know where is exact position of newline(\r\n) on the file like below...


ap

ple

or

appl

e


I also googled many pages but I couldn't find the answer. Should I have to write beginner regex like below? (a\r\npple|ap\r\nple|app\r\nle|appl\r\ne|apple\r\n|)

I need to find more smarter regex to find exact word.

Best design pattern for structured sequential handling

Doing maintenance on a project I came across code, which I find unnecessary hard to read and I wish to refactor, to improve readability.

The functionality is a long chain of actions that need to be performed sequentially. The next action should only be handled if the previous action was successful. If an action is not successful a corresponding message needs to be set. And the returned type is a Boolean. (successful true/false). Just like the return type of all the called actions.

Basically it comes down to something like this.

string m = String.Empty; // This is the (error)Message.
bool x = true; // By default the result is succesful.

x = a1();
if(x) {
    x = a2();
}
else {
    m = "message of failure a1";
    return x;
}

if(x) {
    x = a3();
}
else {
    m = "message of failure a2";
    return x;
}

//etcetera..etcetera...

if(x){
    m = "Success...";
}
else{
    m = "Failure...";
}

return x;

My question is: What is a better structure / pattern to handle this kind of logic?

Main goals are:

  • increase readability.
  • increase maintainability.

Please keep in mind that it is quite a large chain of actions that is being performed sequentially. (Thousands lines of code)

Java - How to remove temporal coupling?

I received from following comments on my code :

It is a procedural design, and there is temporal coupling between lines in method names().

It is quite apparent that what names() is doing—creating a list of names.

In order to avoid duplication, there is a supplementary procedure, append(), which converts an item to lowercase and adds it to the list.

 class Foo {
  public List<String> names() {
    List<String> list = new LinkedList();
    Foo.append(list, "a");
    Foo.append(list, "b");
    return list;
  }
  private static void append(
    List<String> list, String item) {
    list.add(item.toLowerCase());
  }
}

Can any one give me some pointers like how can I improve this design ?

Extending functionality of Strategy pattern

I am developing an app that compares files. I decided to use the Strategy design pattern, to handle different formats, so I have something like this:

public class Report {
   CompareStrategy strategy;
   ...
}


public interface CompareStrategy {
   int compare(InputStream A, InputStreamB);
}

Then, naturally I implement the compare method for different file formats.

Now suppose I wanted to add another method, that deals with certain restrictions for the comparison (e.g. omit a row in case of an Excel or csv file, or omit a node in XML).

Would it be better to:

  1. Add another method to the interface and every implementation (there are few for the moment)
  2. Write a new interface which inherits from CompareStrategy and then implement it?

The second question is: since the differences can be of various types - would it be OK to make a marker interface Difference to enable something like:

int compareWithDifferences(..., Iterable<Difference> differences);

and then go on defining what a difference means for the specific file format?