mercredi 1 février 2017

Can I implement singleton Pattern like this?

Wanted to explore new way to implement Singleton Pattern.Can this implementation be consider as a singleton Pattern ? If No Please give suggestions to improve the code.

 public interface Test {
        Singleton single = new Singleton();
        class Singleton {
            int i = 10;
            private Singleton(){}
        }
    }

Rust stream pipeline creation

Hi I would like get some advice on design for a system that process a stream of data and send it on through a number of elements.

What I a thinking of a something like GStreamer where you have a number of elements with inputs and an output that can be strung together into a pipeline.

My element would not have to deal with complex video or audio it we be simple functions like strip zeros or add a constant.

So lets assume we have a stream input element that reads a data stream from a file. Each data point in my case would be a tuple of a timestamp and floating point value. It would then connect to say an Add element that add 20 to each point. this could then be pass to a third element that only passes the data at 5 minute intervals.

I would be using Rust for this so can use any rust features. I guess I should use channels and allow the elements to run in parallel.

I would be interested in any advice on whether there are similar projects already or design patterns for this kind on thing.

Hide third-party library details c#

I am using third-party libraries (nuget packages) in my C# web application. I want to hide their details from client code so that I can swap these external dependencies without changing client code. I looked at Adapter and Design described here. But still not sure which one I need.

Also, looks like if I go with Facade then unit testing will be a challenge. As Facade holds static instances of dependencies.

Request and Response Objects in Lower Layers

In some API's you can make a call to one of its methods with a Request object as the parameter and you receive back a Response object after it finishes. If we take this same approach, can we just apply it everywhere?

For example, let's look at it from the API's side.

  1. The endpoint has a method named InsertData that takes in a InsertDataRequest's. It's endpoint consumes these requests and sends them over to their coordinator layer.
  2. From the coordinator layer, we start handling this request but need to call private class A at some point to use its FindData() method.

So my question: Is it considered bad design if we have FindData have a method signature of public FindDataResponse FindData(FindDataRequest request)? The coordinator layer at this point would have to make a FindDataRequest object to make the request to the class A and would just parse its response. Are there advantages/disadvantages to this? Am I breaking design principles?

Custom urls and MVC structure?

it has been almost 6 months since i started learning web development, i can tell that i'm proud of what i have been able to achieve after spending all that time learning. you can see a demo here (code source included) : https://www.youtube.com/watch?v=GQmvDDtNtpI i coded this project using (PHP, MYSQL, APACHE, CSS, HTML), i understand that php is not a language that forces you to use classes in order to make things run you can right code in any page and it will run but does it really matter if i used custom links instead of query strings? or following a specific structure such as MVC? or using config files like .htaccess?

thanks for your time.

how to notify observer with 2 arguments change?

I'm new with design patterns. I'm trying to solve this exercise with java about observer design pattern: we have a point class and a segment class

Point{
void translater(int dx,int dy);
double distance(Point p);
}

Segment{
private double longueur;
public Segment(Point ex1,Point ex2){....longueur=ex1.distance(ex2);}

public double getLongueur(){}

}

If we do p.translater x and y of the point change, I want the segment class to be notified. How can I notify observer with the x and y values? Note, I must not change the getLongueur method.

How to prevent calling constructor of one class while having access to its member functions in C#?

I have a class A, and a class AStore. My requirement is to prevent all other methods from initializing an instance of class A, which they should get an instance from AStore. In addition, I also need to access the member functions of A from the instance.

Factory pattern is not suitable for this problem as the constructor of A is still public. Ideally, it should throw compilation error when calling the constructor of class A while having access to its member functions.

Can I get C# solutions to this?