dimanche 2 février 2020

Which design pattern should be used for custom forms reporting?

We have custom forms consist of questions and answers which can be dynamically added. So the data is stored in rows of tables in database. Now the requirements are:

1) Generate report of data in single row. All questions and answers of a form should appear in one row. 2) Some customers wants to manipulate data in their provided scheme while generating report e.g. Show additional system information along with custom form data and conditional checks on dependent questions. 3) Report can be extracted in excel, pdf etc. Moreover there should be a functionality to zip excel or pdf file if multiple reports are to be generated.

Java design patterns program using oops [closed]

Create java design patterns for restaurants having employees as Manager, assistant manager of each department, Employees part of department. Departments: Kitchen Bar Dinning. Accounting. Security Consider Manager has control over all the employees (Hire/Fire any one from restaurant), Assistant manager has control over his department (Hire/ fire anyone from his department only). Employees from department should be equipped to do their respective task like chiefs- cooking.

samedi 1 février 2020

How do I add the elements of several lists in python

I am trying to calculate the total number of convergent hailstone sequences. In the code below I am determining whether a sequence is convergent or divergent for different values of a, b, and x and outputting a list (seems to be a list of lists with one element in each sublist). My issue here is I can't seem to find the TOTAL number of convergent sequences. I would like to add all the 1's in my list and output the final value to obtain this answer. Can anybody please help?

P.S. In the output below, 1 = convergent 0 = divergent.

Here's my code:

def hailstone(a, b, x):
    list = []
    c = 0
    count = []
    for i in range(1, 100):
        if x%2 == 0:
            x = x/2
        else:
            x = a * x + b
        if x not in list:
            list.append(x)
        else:
            break
    if len(list) < 99:
        c = 1 + c
        count.append(c)
    else: pass
    return(count)

def run():
    for a in range(1, 4):
        for b in range(1, 4):
            for x in range(1, 4):
                print(hailstone(a,b,x))      

run()

Here's the output

[1]
[1]
[1]
[]
[]
[]
[1]
[1]
[1]
[]
[]
[]
[1]
[1]
[1]
[]
[]
[]
[1]
[1]
[1]
[]
[]
[]
[1]
[1]
[1]

Also, here's the data type for my list count:

<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>

Do I really need a static class to manage favorites?

Hi have a conception problem. I work on a pro app to calculate some scores. I do it with C# / Xamarin.Forms. I want to manage favorites, so that the user can have a limited score list to find its favorites faster.

I have 4 tabs :

  1. Entire score list ==> navigates to chosen score
  2. Favorites list ==> navigates too
  3. & 4. : not a problem here

So I want that when the user adds/deletes a score from the favorites list, this is changed in the first and the second tab. For the moment I have this :

public static class FavoritesManager
{
    public static ObservableCollection<string> FavoritesList = new ObservableCollection<string>();

    // Indexer does not work because static class ==> this is one of the problems
    // public bool this[string key] { get => this.Favs.Contains(key); }
}

// My ViewModel
public class ScoreListViewModel : ViewModelBase
{
    // Each Category is a List<Score>. Score has 3 properties : string Title, string Detail, bool IsFavorite
    public ObservableCollection<Category> Categories { get; set; }

    public ScoreListViewModel()
    {
        this.InitializeCategories();

        FavoritesManager.FavoritesList.CollectionChanged += OnFavoritesChanged;
    }

    // When favorites list has changed ==> event CollectionChanged
    public void OnFavoritesChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        this.InitializeCategories();
    }

    public void InitializeCategories()
    {
        this.Categories = new ObservableCollection<Category>
        {
            new Category ("Cat1")
            {
                new Score("Foo", "Bar", FavoritesManager.FavoritesList.Contains("Foo"))
            }
        };
    }

    // Command used to add a favorite
    public ICommand AddToFavorites => new Command<string>((fav) =>
    {
        FavoritesManager.FavoritesList.Add(fav);
    });
}

So I have 2 questions :

  1. How to avoid dependency of ViewModel to the static class FavoritesManager ? Do I really need a static class or is there another way to "share" it in real time through different views ? Because if I decide to change favorites management, when I will have 30-40 scores in the list, it will be very difficult...

  2. Is there a way to avoid complete reinitialization of the Categories list each time I change just 1 thing (1 favorite) ? This is, I think, mostly a XAML / Binding question...

Thanks for your help, Galactose

Rest API Design: Why are path variables favored over the body

I've been having a discussion about REST API design at work and I'm hoping someone can answer a question for me.

Most of what I've read on REST API design best practices seem to agree that when doing a PUT, PATCH, or DELETE you should use the URI to identify the resource, and the body to pass any additional data.

So, in a route where you are making an update to the email of user 123, you would have something like this:

PUT /users/123

body:
{
  email: "some_new_email@email.com"
}

My question is why is it favored over something like this:

PUT /users

body:
{
  userId: 123,
  email: "some_new_email@email.com"
}

Pretty much everything I've read seems to agree that the first example is considered the best practice, but I've yet to find anything that explains why that is other than keeping it consistent with the GET requests. I'm not trying to argue against the best practices, just trying to understand why that is favored.

Combining template with factory design pattern, a good practice?

I want to use abstract class, instead of interfaces in simple factory design pattern. In a way it is like combining template design pattern with factory design pattern. Is it a good practice?

Is Double Brace syntax an anti-pattern in Java when used to initialize static constant?

Is Double Brace initialization syntax () really that bad when used to initialize static final constant?

To my knowledge the worst thing about using this pattern is that variable will contain reference to enclosing class, which is very bad especially in production environment. However, this does not seem to be an issue when applied to static constant.

Am I missing something or is it simply a matter of taste in this case?