vendredi 1 mars 2019

Is there a standard name for an empty interface implementation used for a 'null behavior'?

Consider (in C# just as an example) an interface:

interface ILog
{
   void log(string text);
}

Which has the following implementations:

class GUILog : ILog
{
   public log(string text)
   {
      MessageBox.Show(text);
   }
}

class ConsoleLog : ILog
{
   public log(string text)
   {
      Console.WriteLine(text);
   }
}

class FakeLog : ILog
{
   public log(string text)
   {
      //Do nothing
   }
}

Is there a common naming convention for something like 'FakeLog'. Note that the logging context is just an example. The general idea is more that you have an implementation which does nothing...how should you name that? Of course you must assume the client doesn't rely on the implementation doing something to operate correctly. 'Mock' is perhaps close but is more from the testing side of things, and in this case no calls are logged. Maybe 'NOOP'?

MVC,MVP,MVVM - best design pattern for android applications

There are multiple design patterns available for android application. Can any one help me by advising which design pattern is best for developing e-commerce applications like amazon,myntra etc.

Trying to get rid of the "if" chain in a class

its a question mainly about design.

Lets suppose we have a class that has the role of initiating different subclasses of a certain type. The problem comes when the __init__ method receives different parameter for each subtype. Is there any way to avoid the if's inside the function that initializers the classes just to know what parameters to pass in? Maybe some design pattern that I am not aware of. Or is it an outcome of a bad design?

below is an example of what I mean. notice the manage static method that has the if...else... in it and if there were more types of workers, we would have more if's, which is what I am trying to avoid.

from abc import ABCMeta


class BaseWorker(metaclass=ABCMeta):
    def work(self):
        pass


class Worker1(BaseWorker):
    def __init__(self, name):
        self.name = name

    def work(self):
        pass


class Worker2(BaseWorker):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def work(self):
        pass


class Manager(object):
    @staticmethod
    def manage(workers:[BaseWorker]):
        for worker in workers:
            if worker.__name__ == Worker1.__name__:
                w = worker(name="davay")
                w.work()
            else:
                worker(name="ok", age="55")


if __name__ == '__main__':
    workers = [Worker1, Worker2, Worker1]
    Manager.manage(workers)


Thanks!

pattern print with specific lines print using SED

cat sed-examples
this_is_a_file_to_stat_edid
ab
343
13524365476586o
FINEME
OKME
dasfgh
this_is_a_file_to_stat_edid
ab
343
13524365476586o
FINEME
OKME
dasfgh

i want to see the output as this_is_a_file_to_stat_edid FINEME OKME

using sed

tried

sed -n -e '/edid/ {h;n;n;n;H;x;p}h'

it returns this_is_a_file_to_stat_edid FINEME but not OKME

JAVA - How to validate phone?

I am really sad because i have to ask this question..

I have this pattern but it don't work how i want to work.. "^\+(?:[0-9] ?){6,14}[0-9]$"

Now when i type only numbers for phone for example: 08484545 it says me error but i want to have this allowance in my pattern Numbers: 0123456789 Characters: // , + , (), /, - , -

Can somebody help me with this issue i will be very thankful for it. I can not figure it out alone because I don't understand how it works and i am loosing a lot of time for this issue.

Edit: Why not duplicate?

saw it but i want on all places () , also plus need to be in front of the numbers or numbers need to be typed without plus like this 0123456789 or like this (49) 178-178178 or like this (+49) 178-178178 or like this +(49)178-178178 or liek this 0178178178 or 178/178-1787 or like this 0(178)178-1 etc.. i think so that is not duplicate because i tried to import that solution adn it doesnt works how i want.. –

Why not use constructor directly?

I need to create a instance of ScanOptions. The correct code as below.

String pattern = "mykeyprefix_*";
Long cnt = 2000L;
ScanOptions options = ScanOptions.scanOptions().match(pattern).count(cnt).build();

My question is why not just use constructor to create object directly?

scanOptions = new ScanOptions(parttern, cnt);

Or use object Factory to create instance?

options = ScanOptionsFactory.create(parttern, cnt);

So is there any benefit to design code as first case? Could you please explain for me in detailed? thank you very much! here is the spring source code:

org.springframework.data.redis.core.ScanOptions

Creational pattern for generic objects

could someone please help with the best way of returning the concrete implementation in the following scenarios. Say I have:

public interface IThing<TInput> where TInput : RequestBase
{
    string Process(T input);
}

And then multiple implementations:

public class Thing1<T> : IThing<T> where T : ReqThing1
public class Thing2<T> : IThing<T> where T : ReqThing2

In my calling class what is the best way of wrapping the construction of those classes and returning the IThing that I want in a clean, testable way? Thanks