dimanche 2 mai 2021

What files are consider for model , view and controller in MVC design pattern?

In MVC design pattern in android. which file comes under model, view and controller ? files like activities, fragment, adapter, pojo classes etc. How we can separate in context of MVC ?

Csharp design patterns [closed]

The relation between publisher and subscriber can easily be understood as an analogy to magazine subscription.a.A magazine (publisher) isthe business and publishes magazines (data).b.Ifa customer (subscriber) interested insubscription(subscribe/register), the magazine gets delivered to the customer each month after new edition ispublished.c.(unsubscribe/unregister), disconnects subscription and stops sending new editions to the customer as he/she remains no longer a subscriber after unsubscribing.d.Publisher doesn’t know who the customer areand how theyuse the magazine, hejust delivers magazines to the customers because both are bound in a relationship(loose coupling).Actual Problem StatementAssuming, in a real-world publishing business, HyperMediapublishing company hires you as developer and assigns you task to automate their magazine business. The magazine data consists title, number of pages,publishing dateand content.HyperMediawants anyone who is interested in magazine subscription, to facilitate subscribe/register and unsubscribe/unregister online. The subscribers will be sentan online digital copyin a PDF format each month when it gets published.Required SolutionUsing C# write a solution for HyperMedia publishing business by understanding the above written problem statement in the analogycontext.The solution you provide must be implementing the required design patterns that justify the reusability, extensibility, and maintainability.

Pattern where main application is launched as a sidecar?

Containers made the sidecar pattern ubiquitous. However, a few years ago I recall reading about a pattern for desktop applications where, instead of having a monolithic desktop app handle logging and monitoring, a parent process was responsible for launching the main desktop app, perform health checks and monitoring its lifecycle, and even handle over-the-air updates or relaunch the desktop app in case of failure.

In this case, the main desktop app would be designed as a kind of sidecar which handles the bulk of responsibilities, while the parent process handled monitoring.

Does anyone happen to come across this pattern?

samedi 1 mai 2021

Is it a necessary trade-off that using smart pointers requires my class to be publicly instantiable?

I have a base product class with a few private members and a public getter that derived classes inherit. I would like to disqualify instantiation, since the class is intended for use with an abstract factory. I thought protected con/destructors might work, however, this breaks my smart pointers. Friending seems like a useful disaster. Is there a well-known solution to this, or should I resign myself to the fact that any client who has the factory injected must also know enough to instantiate the base product?

class Product
{
private:
    char type_name;
    char size_name;
public:
    Product(char, char);
    virtual ~Product() {}
    void Print();
};

How to do a simple pattern coding

If I want to have the numbers coded like this, could you give me some suggestion about the codes?

1
2 3
6 5 4
7 8 9 10
15 14 13 12 11
...........

Thanks!!

Design patterns for chaining data transformations methods using pandas

I receive monthly a csv file that has some columns. Regardless of what columns I receive, I should output a csv with column C1, C2, C3, ... C29, C30 if possible + a log file with the steps I took.

I know that, the order of my data transformations should be t1, t2, t3, t4, t5.

t1 generates columns C8, C9, C12, C22 using C1, C2, C3, C4
t2 generates columns C10, C11, C17 using C3, C6, C7, C8
t3 generates columns C13, C14, C15, C16 using C5, C8, C10, C11, C22
t4 generates columns C18, C19, C20, C21, C23, C24, C25 using C13, C15
t5 generates columns C26, C27, C28, C29, C30 using C5, C19, C20, C21

I cannot control what columns I get in my input data.

If my input data has C1, C2, C3, C4, C5, C6, C7 columns I can generate all the C1 ... C30 columns.

If my input data has C1, C2, C3, C4, C5, C6, C7, C8, C10, C11, C17 columns I can generate all the C1 ... C30 columns, but I should skip t2, as it is not necessary

If my input data has C1, C2, C3, C4, C6, C7 I can only do t1, t2, t3, t4. I cannot run t5, therefore I should create C26, C27, C28, C29, C30 columns with NaN values only and I should add in the log "Cannot perform t5 transformation because C5 is missing. C26, C27, C28, C29, C30 are filled with NaN values"

My t1, t2, t3, t4, t5 are already created, but I don't know how to organize the code in an elegant manner such that the code repetitions are minimal.

I had to develop my code in a very short amount of time. Consequently, all my t1, t2, t3, t4, t5 methods look like

def ti(df):
    output_cols = get_output_cols()
    if output_cols_already_exist(df, output_cols):
        return df, "{} skipped, the output cols {} already exist".format(inspect.stack()[0][3], output_cols)
    else:
        input_cols = get_required_input_cols()
        missing_cols = get_missing_cols(df, input_cols):
        if missing_cols == []:
            // do stuff
            log = "Performed {} transformation. Created {} columns".format(inspect.stack()[0][3], input_cols)
        else:
            for col in input_cols:
                df[col] = np.NaN
            log = "Cannot perform {} transformation because {} columns are missing. {} are filled with NaN values".format(inspect.stack()[0][3], missing_cols, output_cols)

Also, I use the functions in the following way:

text = ""
df = pd.read_csv(input_path)
df, log_text = t1(df)
text = text + log_text + "\n"
df, log_text = t2(df)
text = text + log_text + "\n"
df, log_text = t3(df)
text = text + log_text + "\n"
df, log_text = t4(df)
text = text + log_text + "\n"
df, log_text = t5(df)
text = text + log_text + "\n"
df.to_csv("output_data.csv", index = False)
logging.info(text)

As you can see, my code is ugly and repetitive. Now I have time to refactor it, but I don't know what would be the best approach. I also want my code to be extensible, as I am also thinking about adding a t6 transform. Can you help me giving some directions / design patterns I could follow? (I am also open using other python libraries beyond pandas)

In Smalltalk, what’s the best way of defining an associative binary message when the sender and argument are of different types?

Suppose you have a class Foo, and that you want to be able to multiply a Foo by a Number to get another Foo, using ‘@@‘ as the multiplication sign.

Since multiplication is associative, it would be nice to be able to write:

| f a b |
f := Foo new.
a := 3 @@ f.
b := f @@ 3.
self assert: a = b

This requires not just adding the binary method “@@” to Foo, but also to the Number class. So you end up with essentially the same method in two different places (along with a circular dependency), which seems rather inelegant.

So I'm wonding, in Smalltalk, is there any other way to create associative binary messages where the sender and argument are of different types - one which doesn’t require you to define the same message in two different classes?

If not, is possible to create this ability using Smalltalk itself (ie. add classes/methods which automate the management of associative binary methods, without changing the actual SmallTalk language or VM)?