dimanche 25 novembre 2018

Is there any reference design or writings for the program/workflow process in Java (OOP)? [on hold]

Is there any reference design or writings for the program/workflow process in Java (OOP)?

This is the short version if the question which I am asking here but what follows is the longer version of it.

I have searched on internet about this topic and also in table of contents of many books to find information about the problem which is when to use static or not a static code for implementing the part behavior of a program.

It can be any other program but in my case it is an program which is manipulating (set values) the properties of objects which are part of a collections. The process is well known and is not changing much. Parts of it is implemented as static methods.

When reading the principles of OOP then the suggestion there are never based on static code. The lack of information about the static way of programming results into a dilemma, to use static content or not, and beside that if the usage of static way of programming is not a bad practice then another question is when precisely should it be used.

//not static example
...
public void manipulate(Object obj) {
    ObjectManipulator objectManipulator = new ObjectManipulator();
    objectManipulator.apply(obj);
}

//static example
...
public void manipulate(Object obj) {
    ObjectManipulator.apply(obj);
}

Both ways have their advantages and disadvantages.

  1. not static methods

    • creating objects - allocating memory, setting memory free - performance costs, less memory.
    • testing - Method can be mocked (JUnit, Mockito)
  2. static methods

    • not creating objects - memory allocation at the beginning once - less performance costs, more memory.
    • testing - Method can not be mocked (JUnit, Mockito) - but Powermock works which is bad practice?

An conversation about usage of static methods can be found under the question Java: when to use static methods.

But back to my question Is there any reference design or writings for the program/workflow process in Java (OOP)?

I am a little but suprised that I can't find anything on this topic in the books where the basic of OOP and its principles are described.

Aucun commentaire:

Enregistrer un commentaire