vendredi 23 décembre 2016

Design approach in MVVM

So i want to create a wpf form which shows the ressource planning for each week. The outcome should look like this:

enter image description here

I'm now struggling with the design of the viewmodel. Let's say I start like this (the child objects are indented):

WeekCollection
    Week // (from model)
        ProjectCollection
            Project // (from model)
                DayCollection
                    Day // (from model)
                        EmployeeCollection 
                            Employee // (from model)

Where I'm now struggling is, that with this approach, the classes in the model would be expanded to hold information, that is only needed for this particular viewmodel of the weekly planning. I.e. the class for day should have a date property, but not hold a collection for employees.

On the other hand, if I create a seperate viewmodel or a derrived collection class for each collection, wouldn't I get thousands of classes for the whole application?

So the question is, what is the best/usual way, to model the classes in an mvvm application, if the structure is like this?

What is the correct way to implement a Creator Class and the Class itself design in Java?

so I am facing a question here. I am trying to decide on a design for all my Classes and they're Creators.

For example I have 2 classes, Level and LevelLoader: The design I have come so far is: This is Level class:

public class Level implements Serializable{

    private byte[] map; 

    Level(LevelLoader loader){
        map=loader.getMap();
    }

This is the Creator:

public interface LevelLoader {

    public Level loadLevel(InputStream stream);

    public byte[] getMap();

}

So for example to create a level instance in main file i'll write: TextLoader is implementing LevelLoader interface above:

File file=new File("src/Level/level2.txt");

Level level1=new Level(new TextLoader(file));

So I am curious what is the most logic way to connect between the two ?

Tahnk you.

C# - Pattern for iterating over predicates

I made a pattern which i dont really like.

It is as the following:

result = findResult(getFirstPriorityElements(listOfPossibleResults));
if (result!= null)
{
 return result;
}

result = findResult(getSecondPriorityElements(listOfPossibleResults));
if (result!= null)
{
 return result;
}

etc..

Basically i'am creating sublists based on a couple of rules. After creating the sublist, i try and find a specific element in it. If i dont find, i move on to the next priority, and so on.

I would like a solution where i can iterate over these criterias, until i find a solution. But i dont know how to get them to a format which i can iterate over.

Design to access elements of object owner

Let's say I have two classes:

Class A {
  B b;
  Foo bar;
}

Class B {
// some stuff
}

Since an object of type A owns an object of type B, some stuff of B could be accessed by A. What would be a good design, if an object of type B has to has access to it's owning object (of type A)? E.g. if I have an object of type B and want to get the bar value of the object it is a member of.

Would it be good practise to add a reference to A to B everytime a B is created?Or some kind of delegate pattern?

jeudi 22 décembre 2016

Creating a scalable software best practice

I'm a novice programmer, And I'm trying to build a large scalable software, so a new features could be added easily in the future.

What's guide or book do you recommend to me for building a scalable and maintainable software ?

Should I always use design patterns with software architecture like 3-tire ?

How to avoid cyclic calls from a flow?

There are 4 classes as mentioned below -

  • class A having 2 methods f1() and f2().
  • class B having method f3().
  • class C having method f4().
  • class D having method f5().

Now the following is true about the above classes -

  1. f1() calls f3().
  2. f3() calls f4().
  3. f4() calls f5().
  4. f5() calls f2().

Is it a bad design? If yes, how can this design be improved??

Proper State Pattern

Im curious about State Pattern and how to design them correctly. On my previous writen exam I failed on this question:

State Pattern

A PinBallGame can be in three states. In each of the states, a different music loop is played as follows:

  • idle: no music is played.
  • NormalPlay: music is played by calling the static method MusicOutput::PlayNormal().
  • Multiball: music is played by calling the static method MusicOutput::PlayMultiball().

Please complete the following class diagram using the State pattern. Please alfo fill in the method bodies.

enter image description here


On my exam I was thinking of a State Diagram, thereby I failed. Now I want to know how I was supposed to write it.

Here is my answer if I would get the same question today:

enter image description here

Am I on the right track? Any feedback is good! Thanks in advice.

/P