lundi 1 février 2016

Function that acts like a decorator, but uses mutation instead of wrapping?

A decorator adds additional functionality to an object by "wrapping" around the original value.

Is there a name for an object or function that ingests a pre-constructed object and adds additional functionality to it via mutation?.

Example:

function mutatesObjects(target) {
  target.additionalFunctionality = "I've been mutated!";
}

This is similar to a contrcutor or factory except that it is adding functionality to an object that was already created.

Is there a name for this pattern?

How to avoid dependencies on unused third-party libraries

In the company where I work we have a mix of common library base (several C++, C++/Cli and C# dll's) which grow big over the years. We are planning to refactor it, therefore I'm trying to learn the best practices how to do it. Most of the new design is clear for me, however I'm not sure how to deal correctly with 3rd party dependent code.

At this moment the library is dependent upon different technologies like OpenCV, OPC, MySQL, MSSQL, AVT Vimba, Ximea Api, Microsoft Enterprise Libraries, .Net framework, TwinCat, Dave, Cuda, ...

One of my biggest problem with the current design is that in most of the cases when I have to use only few functions from the common libraries, I end up with an exe file, 2-3 common libraries and 30-50 3rd party libraries. At this moment the code is divided across the libraries based on their domain, which is not really good, because it forces me to release my application with libraries which the application don't really need.

So, how do you guys avoid this kind of hard dependencies on 3rd party libraries?

Is it a good idea to divide the code based on domain and also technology? Lets say the Cameras.dll is dependent upon AVT Vimba, Ximea and OpenCV. My idea was to divide it this way:

  • Cameras.dll -> no dependency on 3rd party libs
  • Cameras.Avt.dll -> dependency on AVT
  • Cameras.Ximea.dll -> dependency on Ximea
  • Cameras.OpenCV.dll -> dependency on OpenCV

Creating in memory message bus java

I have in one of the assignment to create in memory message bus. I have some understanding of message bus functionality but since it is quite open ended question want some suggestions that what features I can have in my assignment and what all design heuristics I should keep in my mind.

Thanks,

Amandeep

Regex with multiple repetation

I have difficult time with regex right now.

I am able to debug the regex in Regexbuddy but somehow it is not working in C#.net.

For example.

My Input string:-

--8W1_805_431____0210_A01_0002_L--;%{PE}%R  
8.2.24,%MKUKATPBASIS,%CCOMMENT,%VNORMAL,%P 2: --8W1_805_431____0210_A01_0002_L--
;ENDFOLD  

;FOLD PTP SG003920 Vel=100 % PDAT5 ServoGun=8 Cont=OPN Part=2.65 mm WeldTimer=WTDAT1 Tool[1]:zc1 Base[1]:510wz1;%{PE}%R 4.1.25,%MKUKATPSERVOTECH,%CSpotTC,%VPTP,%P 1:PTP, 2:SG003920, 3:, 5:100, 7:PDAT5, 9:1, 11:1, 13:OPN, 15:2.65, 18:1, 21:0, 24:0, 27:5, 30:0, 33:WTDAT1
$BWDSTART=FALSE
PDAT_ACT=PPDAT5
FDAT_ACT=FSG003920
BAS(#PTP_PARAMS,100)
EG_SPOT_POINT_NAME[]="SG003920"
EG_EXTAX_ACTIVE=EG_SERVOGUN_EXAXIS[1]
EG_THICKNESS=2.65
EG_GUN_FORCE=1
EG_COMP_HELP=0
EG_COMPENSATE_PATH=0
EG_PROGRAM_NUMBER=003920
EG_HELPPOINT=EG_CHTIP(XSG003920)
PTP EG_HELPPOINT 
EG_APPROX_OPEN=FALSE
CMD=#SPOT
EG_SPOT_POINT=EG_HELPPOINT
EG_SPOT( WTWTDAT1 )  
PTP EG_HELPPOINT C_DIS
CMD=#STOP_POINT_END
EG_SPOT_POINT=EG_HELPPOINT
EG_SPOT( )

  ; --8W1_112_431____0210_A01_0001_L--;%{PE}%R 8.2

;FOLD PTP SG003918 Vel=100 % PDAT7 ServoGun=1 Cont=OPN Part=2.65 mm WeldTimer=WTDAT2 Tool[1]:zc1 Base[1]:510wz1;%{PE}%R 4.1.25,%MKUKATPSERVOTECH,%CSpotTC,%VPTP,%P 1:PTP, 2:SG003918, 3:, 5:100, 7:PDAT7, 9:1, 11:1, 13:OPN, 15:2.65, 18:1, 21:0, 24:0, 27:5, 30:0, 33:WTDAT2
$BWDSTART=FALSE
PDAT_ACT=PPDAT7
FDAT_ACT=FSG003918
BAS(#PTP_PARAMS,100)
EG_SPOT_POINT_NAME[]="SG003918"
EG_EXTAX_ACTIVE=EG_SERVOGUN_EXAXIS[1]
EG_THICKNESS=2.65
EG_GUN_FORCE=1
EG_COMP_HELP=0
EG_COMPENSATE_PATH=0
EG_PROGRAM_NUMBER=003918
EG_HELPPOINT=EG_CHTIP(XSG003918)
PTP EG_HELPPOINT 
EG_APPROX_OPEN=FALSE
CMD=#SPOT
EG_SPOT_POINT=EG_HELPPOINT
EG_SPOT( WTWTDAT2 )
PTP EG_HELPPOINT C_DIS
CMD=#STOP_POINT_END
EG_SPOT_POINT=EG_HELPPOINT
EG_SPOT( )
;ENDFOLD


Regex Pattern:- --(?<PName>8W.*?)--.*?(?<MType>PTP|LIN).*?(?<PointNa>SG) 

The output has to be like this for the group PName.

8W1_112_431____0210_A01_0001_L

8W1_805_431____0210_A01_0002_L

As I run this regex in c# its returns always false.

Please any one guide me what is wrong over here.

Thanks in advance.

Is the factory pattern what I need?

I'm just wanting some clarity on my thinking before I start building something. I'm building an importer and the importer will always accept the following data:

[SKU, Name, Color plus 243 others]

However, the data sent to the importer could use different column names and in different file formats (CSV or excel plus others) because of the vendor. So do I need to create some sort of mapper to say X column means X column in my DB?

I'm thinking the best way to do this is to build an interface which then each vendor has its own implementation of it that contains a column name mapper then uses a factory pattern to build the final object.

I could be totally wrong, so has anyone had experience with building such things and what did you use?

Thanks Oli

New Project starting point

So let’s say you are going to start a new project with a bunch of classes, and ready user case etc. How do you start coding it? Do you take one particular class implement it as good as you can, then refactor it to use for example interfaces, or do you start by briefly implementing classes with bunch of not implemented exceptions. Or maybe something different. Basically I want to now, what workflow should I choose?

Proper way to pass values

Assuming that we have the following class, is it better (in terms of oop) to pass the object of class Foo to Bar constructor rather than pass only the arguments baz and qux to Bar constructor?

class Foo
{
    public $baz, $qux;

    public function __construct($baz, $qux)
    {
        $this->baz = $baz;
        $this->qux = $qux;
    }

    public function main()
    {
        $bar = new Bar($this);
        //OR
        $bar = new Bar($this->baz, $this->qux);
    }
}