Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Best approach to comply to object oriented philosophy for list?  RSS feed

 
Christian Klugesherz
Ranch Hand
Posts: 103
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a question relative to Java programming style and approach to be as compliant as possible with "object" philosophy
Perhaps a non-sense question, but just to have your inputs   .

I have declared a Class Measure of "measure elements" with constructor and all methods like:


Afterwards, I'm instanciating a list measurePL of this class Measure elements
Like following


Until now all is clear :-)

Now to my philosophy question :-)
In my program I have to work with this list, and the question is Where to declare the method which will manipulate this list :: method "updateAllMeasureListElem "



Several approaches on that
1) To declare in the class where I'm needing this method, example in class WinDisplay {.. }
(+) Can be declared as private
(-) I'm manipulating an object outside of its class definition, -->  loss of the object "view"
(-) In case I have to use this method in another class, this method must be static      
2) To declare as static in class Measure()
   (+) I Keep the manipulation of "Measure" object in the corresponding class (~same object type)
(-) I have to use a static Method to call this Method,  and class  "Measure" is not by sense a List !
To be called further with: Measure. updateAllMeasureListElem()
3) To declare a new class composed, of only the list, == (a container of the list)
(+)  The method is inherit of the class and the instantiated variable will call the method naturally (see below)
(-) It may be unnecessary to go on that approach




What is the best approach to be compliant as much as possible to Object oriented philosophy for list manipulation ?
Solution: 1 -2 - 3 - ... ?

Thanks to all for your comments.

Christian




 
Campbell Ritchie
Marshal
Posts: 54909
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by giving all those fields meaningful names. The fact that they have to be followed by comments explaining them shows they are badly chosen.
The int showing which value shou‍ld be computed looks poor design to me. I have my doubts about the whole class. Do you have a state where you are supplying pressure and temperature and you want to calculate enthalpy? Are you passing two out of three variables and calculating the third? I am not happy about your design, I am afraid. Can you pass an object to a method which takes two values and calculates the third? Can you do that with an enumerated type? That Java® Language Specification might be difficult to read, but look at all its examples, because one is similar to what might help you here.
What is happening in the main method? Are you creating a new object with a new List as its field? How are you populating this List? Is that List empty when you iterate it? Why has that List not got private access (first post, line 3)?
Don't write comments that only tell us what we already know. // Comments are intended to finish off one line, and shou‍ld therefore be short. Don't write comments occupying several lines simply to tell us a constructor is following, which we can see for ourselves. Rather write /** documentation comments */ to expain to users how to use that constructor.
 
Junilu Lacar
Sheriff
Posts: 10929
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Klugsherz wrote:Until now all is clear :-)

Unfortunately, it's not 

Perhaps in your head it's clear but to anyone who doesn't have a psychic connection to you and can hear you thinking in your native language as whatever ideas this code is trying to reflect bounce around in there, it's not clear at all. What does this Measure object represent? Enthalpy? Pressure? Temperature? All of these? Whatever your answer to just these few questions, it will demonstrate that you've already broken some principle(s) of object orientation.

However, without even answering any of those questions, the fact that the intent of the Measure class is not immediately clear shows you've violated one basic intent of OOP: abstraction. One quick look at a properly designed class and its API should make it clear what set of information and behaviors the class represents. This is not the case even with the few lines of code you claim is "all clear".
 
Christian Klugesherz
Ranch Hand
Posts: 103
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, you cannot understand what is clear in my head :-)

I will try to ask my question in a different way

Enumeration





Variable " measureL" instantiated as a list of "Measure" elements



Now I have to compute P and T in different manner depending of enumeration : MeasureObject

And again my question, where would you declare this method: updateAllMeasureListElem()  ?

1) To declare in the class where I'm needing this method,
     (+) Can be declared as private
     (-) I'm manipulating an object outside of its class definition, loss of the object "view"
2) To declare as static in class Measure()
     (+) I Keep the manipulation of the object in the corresponding class
     (-) I have to use a static Method to call this Method,  and class  "Measure"  is not by sense declaring as a List !
3) To declare a new class composed, only of the list, ( == container of the list)
     (+)  The method " updateAllMeasureListElem " is inherit to be called through the class (see below)
     (-) ???



Thanks



 
Christian Klugesherz
Ranch Hand
Posts: 103
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something which is not clear for me. :-(
Can you please help ?

Let us still consider the Measure class.
The objective of this class is to collect external: Temperature, Pressure, + other gas features

Some of the fields in the Measure class are related together based on the Enthalpy (gas) features.
In my application, Enthalpy is a class itself which define “exactly the properties of gas ” + the “Methods” for conversion between
* Pressure to Temperature
* Pressure to Enthalpy (H)
* H to Pressure
* …

In my class Measure, I need to convert P (Pressure) to T(Temperature)

What is the best approach.
1) To consider the Measure Class as extended to Enthalpy (inherit)
2) To Define the Enthalpy conversion methods as static, and so, to be available from outside of Enthalpy Class
3) ??

Thanks in advance for sharing your approach

Christian
 
Campbell Ritchie
Marshal
Posts: 54909
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid the best approach is to start from scratch. Write down on paper what you are planning to do, and what formulae you wish to use.
 
Junilu Lacar
Sheriff
Posts: 10929
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One question: are you using "measure" as a noun or verb? Enthalpy is a measure of energy in a thermodynamic system (from Wikipedia) - so what abstraction are you trying to represent by making your Measure class extend an Enthalpy class? Remember, when it comes to OO, inheritance represents a Generalization-Specialization relationship; many people mistakenly think of it as a Parent-Child relationship, which is why we discourage that point of view and encourage the Generalization-Specialization point of view by referring to the associated classes as "superclass" and "subclass" rather than "parent class" and "child class".
 
Christian Klugesherz
Ranch Hand
Posts: 103
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hummm.
I think I have to look back on oo concepts.
 
Christian Klugesherz
Ranch Hand
Posts: 103
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps to clarify what was the basic reason I asked the question above.
I did hear that "static variables" in Java should be avoided as much as possible.
By sense, I interpreted that this should also be the case for static methods
So my approach in the "object" philosophy, was to fulfill "my" imposed goal. == avoid static methods

In other words
Reticence to use solution

Preferred solution


But I guess that I was wrong. :-(
By taking into account all your remarks,
* renaming the field in my class with something more understandable,
* renaming the class Measure with MeasurePoint:
* considering that Enthalpy is an object describing the Enthalpy feature of the gas.
the retained solution is
2) To declare "updateAllMeasureListElem " as static method in class MeasurePoint with passing as parameter List<Measure> measureL

Any comments or suggestion on that ?

Merci

Christian

 
Campbell Ritchie
Marshal
Posts: 54909
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by writing down what you intend to do, in plain English French and post it here in plain English.
Earlier, you wrote:. . .
"Température des gaz BP\n après surchauffe interne\n et avant compression", . . .
"Température des gaz HP\n en fin de compression\n (Cloche du compresseur)", . . .
"Pression du début de condensation\n (Mesure HP Manifod)", . . .
"Pression de fin de condensation\n (Mesure HP Manifod)", . . .
"Température Départ Eau Captage",
. . .
I presume those mean
Gas pressure (LP) after internal superheating and before compression
Gas pressure (HP) at the end of the compression [cycle] (compressor's collection chamber)
Pressure at start of condensation [cycle] (HP manifold)
Pressure at end of condensation [cycle] (HP manifold)
Temperature of water exiting condenser
Where HP=haut pression=high pressure and BP=bas pression=LP=low pressure. Are you building a steam engine for a ship or something?
 
Campbell Ritchie
Marshal
Posts: 54909
155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a rule of thumb about things static, in three parts:-
  • If you have a good reason to make it static, then it shou‍ld be static.
  • 2: If you don't have a good reason, then making it static is a mistake.
  • 3: The compiler error about non‑static is a bad reason.
  • Things static belong to the class; static methods must be independent of the state of any instance variables. So if you can say that a method does nothing with any instances, it can be static. Beware of this dubious classification of methods.

    Make everything instance (=not static) unless you have a good reason to make it static.
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Perhaps a misunderstand in my former question.
    The example chosen above could be anything.
    The question was more to have a feedback of Java oo,

    To know if it is preferable to use
    * static method
    ClassName.StaticMethod()
    Or
    instanceVariable.Method()

    In my example above, only solution 3 could fulfill my constraint (certainly ridiculous constraint)
    3) To declare a new class composed, of only the list, == (a container of the list)
    (+)  The method is inherit of the class and the instantiated variable will call the method naturally (see below)

    Relative to your question. Yes translation is correct. But not a ship, but a heat pump
    pac.png
    [Thumbnail for pac.png]
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Always use ClassName.staticMemberName.
    Please post a description of the workings of the heat pump, along with any formulae used to calculate the figures for the graph you showed in the screenshot.
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Our answers crossed.
    Campbell Ritchie wrote: if you can say that a method does nothing with any instances, it can be static.

    Understood.
    Conclusion:
    So to my example, manipulating a list of object: measureL = new ArrayList<Measure>();   through method, "updateAllMeasureListElem()"
    Considering the method "updateAllMeasureListElem()" using only  public methods of the individual class "Measure"
    "updateAllMeasureListElem()"  has to be considered as static , and for sense declared in the class "Measure"
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Campbell Ritchie wrote:any formulae used to calculate the figures for the graph you showed in the screenshot.


    There is no formula, except of the saturation curve in RED where you can find the data (Enthalpy, Pressure) on Internet
    The figure is a picture that you can smooth with a slider, and right/left/up/down/zoom adapt to the saturation curve :-)

    Capture.PNG
    [Thumbnail for Capture.PNG]
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Describe what you want your method to do before you decide what the method is called or how it is written.
    I think you are going to have to supply a description of the heat pump, then you can work out what classes to use and which methods each shou‍ld have. If there is no formula, then simply write, “pressure as on enthalpy diagram at coordinates 123.45, 234.56,” for the time being.
     
    Junilu Lacar
    Sheriff
    Posts: 10929
    158
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Christian Klugesherz wrote:
    Conclusion:
    So to my example, manipulating a list of object: measureL = new ArrayList<Measure>();   through method, "updateAllMeasureListElem()"
    Considering the method "updateAllMeasureListElem()" using only  public methods of the individual class "Measure"
    "updateAllMeasureListElem()"  has to be considered as static , and for sense declared in the class "Measure"

    I think you're getting caught up in the mechanics and missing the point of object-orientation. For me, object orientation is a way to manage complexity by allowing you to think in more abstract terms. The fact that your names include details of the implementations goes against this goal. "List" and "elements" are terms that are particular to Java, not the calculation of enthalpy. If anything, your methods should be named things like totalEnthalpy -- that name has everything to do with your intent and makes no mention at all about the implementation.  It allows you to think in terms of the problem domain (thermodynamics), not the solution domain (Java).

    My rule of thumb for deciding between static vs instance variable is pretty straightforward: If the method requires information that only an instance can provide, then I make it an instance method. If the method can do its work based solely on information that can be passed in as parameters, then it's probably better to make it a static method. I say "probably better" because I have to look at the parameters and where they are coming from first. If they are not coming from a single object or from related objects, then I'll go with a static method. If the parameter values are coming from a single object, then it might be appropriate to make it an instance method that takes no parameters but accesses the fields directly. It's a little more complicated when the parameter values are coming from multiple objects but my decision process basically involves trying to find a relationship between the objects that provide the parameters. If there is a relationship, it may be appropriate to have an instance method that takes the other object as a parameter or a list of other related objects as a parameter.
     
    Junilu Lacar
    Sheriff
    Posts: 10929
    158
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Of course, now I realize that saying my process is simple and straightforward is a bit of an oversimplification. As with OO design, something that seems simple on the surface can be hiding a lot of complexities that lie beneath.  One thing that helps me is never assuming I'm right about something. Always leave open the possibility that each decision you make has a better alternative. So as I said, if I decide to make a method static because it only uses parameters that were passed to it, I don't stop there, I have to look at the parameters and see where they come from. Then I'll look at the motivation for assigning those parameters their values and their scope. Maybe there's a better way to manage those values. The reason I don't end up doing long trackbacks each time I make a decision is that I develop incrementally and write automated tests as I go. Each step of the way, I try to make the design make the most sense. So I stop going back over my decisions at the point where the design last made the most sense. If you do incremental and iterative design and testing, then that point isn't going to be too far back.

    How does this pertain to your question? Well, it's kind of a long-winded way of saying that I don't think your code makes a whole lot of sense and I think you've buried yourself in a hole where you're going to have to track back to a number of layers of decisions about your design. At this point, I think Campbell's suggestion to just start over from scratch will be quicker, rather than try to untangle the small Rat King's tail you seem to found yourself stuck with.
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Please supply a simple description of the heat pump, maybe not more than five lines, and let us see if we can't extract some classes from your description
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for your involvement in the way to fix my issue.
    Don’t misunderstood, even not Object Oriented through courses, I have tried, since the beginning of programming, to think object .

    So I will try to explain :
    A heat-pump is composed of different elements
    * Circulator
    * Compressor
    * condenser
    * Expansion Valve
    * Heat Circuit
    *
    * Refrigerant gas
    Each element has been declared in an individual Class.
    Together, all these elements are constituting of a Head Pump.

    Based on the fact, that you can combine, a
    * specific Circulator, with a
    * specific Compressor, with
    ..
    ..
    to configure the Head Pump, I have created a class PAC (Other name in French of a Head Pump) which instantiate variables, being  a list of all these elements



    This I this guess OO.

    Also, I can add, new individual items, and combine later, in order to simulate any Head Pump. (

    But here the question is related to compute the performance of a Real Head Pump.
    (The other name of performance = COP)

    I have created a class cCop which has, as instance variables Enthalpy values H1,H2,H3, Temperatures T0,TK... and methods which compute different performances: 
    Like next (Consider this is very basic approach)



    Now considering that the only elements that you can measure on a Real head Pump are: Temperatures, Pressures, mass flow,.. BUT not Enthalpy (H)
    Enthalpy has to be computed thanks to Enthalpy Gas feature.
    Enthalpy gives the relation between P,T.
    Also Enthalpy is depending of the GAS.
    You can find data of Enthalpy in Internet / gas.

    So I have created a class enthalpy, which will read the gas feature in a file, and will describe the Enthalpy CURVE



    Finally, to compute performance, == feed Class cCop, you have to pick the Measure values (Pressure, Temperature) on a real Head Pump.

    Taking into account that there are some restrictions, because
    * there must be couple of information (P,T)
    --> before to call the conversion in Enthalpy Class
    Also user can manually move the points in the Enthalpy graphic to match with the adequate H
    I have created a class Measure where you will find
    * the different parameters measured on a Head Pump (T1,T2,.. P3.) see the picture above
    Each point having following feature



    Conclusion
    I have a list of all the measured collected variables (Temperature and Pressure)
    Going through this list, with method :" updateAllMeasureListElem" I will
    * determine the right couple to compute H = Haprox
    -->  For that I'm needing enthalpy conversion. --> reason I have considered Measure Class a child of Enthalpy Class
    * consider either Hreal  if user has chosen to pick the H graphically from the Enthalpy diagram

    Now to my question: where to put this Method.

    Nevertheless:
    Since I have started this topic, I have started to train in UML.
    I will start to consider my problem in a different way .

    This answer is a bit long, but I preferred to clarify, just to show that from the beginning I have tried to consider this approach seriously.
    But I agree, as long as I feel not confident with my approach I will continue :-)

    Christian


     
    Junilu Lacar
    Sheriff
    Posts: 10929
    158
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Christian Klugesherz wrote:
    Since I have started this topic, I have started to train in UML.
    I will start to consider my problem in a different way .

    I doubt that will help you much. If anything, you'll get even more lost. That's like studying Egyptian Hieroglyphics when you don't even know the Egyptian language. UML is just a notation and as such, there are many nuances it cannot capture. I don't even use UML and I've worked in this industry for more than twenty years. I do, however, understand OO principles.

    One trap I see you have fallen into is that you're trying to model your code after the real-world objects. That seldom works out well, especially for the kind of things that you seem to want to do.

    The difference between the description that you have provided and what Campbell and I have been asking for in terms of the question, "What do you want to do?" is like the difference shown in the following imaginary conversation:
    Person 1: Tell me what you want to do.

    Person 2: I want to use a for-loop to iterate over this list of Strings that I want to convert to numbers, then I want to add all of them up to get another number.

    (demonstrates with an example)

    Person 1: Oh, so you want to get the sum of all the numbers from 1 to 100, for example?

    Person 2: Yes!

    Person 1: Well, why didn't you say so in the first place?

    Person 2: Didn't I do that? I thought that's what I did!

    Person 1: No, you told me HOW you wanted to do it, not WHAT you wanted to do.

    Person 2: I see...

    Do you see what we're trying to get from you now?
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done giving a description, but why have you written the code? Then where do the abbreviations T3 TK P.T. come from? When you start asking questions like, “where to put this Method,” we shall have to ask, “Why do you want that method?”
    You need to make the description simpler:-
    A heat pump cools off a cool area and heats up a warm area.
    That is the simplest description. You will have to make it bigger than that:-
    A heat pump cools off a cool area and heats up a warm area. It does that by evaporating a fluid in the cooler area and condensing it in the warmer area.
    As long as you aren't using some sort of Peltier effect, you shou‍ld be able to create a more complicated desccription:-
    A heat pump cools off a cool area and heats up a warm area. It does that by evaporating a fluid in the cooler area and condensing it in the warmer area. The heat pump forces a gas under pressure into part of its circuit where it condenses and releases latent heat of vaporisation. The fluid passes into another part of its conduit which allows where the pressure is nower, and evaporates, taking latent heat of vaporisation from its surroundings.
    Apart from the gas, I have not yet mentioned any of the parts of the circuit. No valves, sensors, or anything. Now you write such descriptions, gradually adding details. You will eventually get to describing things like valves and pressure sensors.

    But, as Junilu has suggested, do you want to know about valves and sensors? Do you need more than a few pressures and temperatures around the circuit?
     
    Liutauras Vilda
    Marshal
    Posts: 4270
    256
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why you writing so many useless comments? Have you been told by your instructor? For example:
    Now what person needs to do when scrolling down, he needs to carry on that information given in the comment and persist in his or her head in order to remember what this P means. That might wouldn't be a problem, BUT, there are T, P0PK and some more or a same kind, so you need to remember them all, or you have to introduce such comments everytime you use such variable, which is of course wouldn't be a good idea - more comments. Now if appears you have been mistaken about something, beside rewriting the code, you need to rewrite all comments too.
    How about having:
    It is super clear. Unless you're under pressure

    Another thing - consider avoiding painting with comments, not sure how for anyone else, but personally for me they give a feeling when you don't know what to do next, you start painting, it just makes code way more difficult to read as you need to scroll more up/down and in your case also left/right, which is the worst case. Campbell says there are more worse scenarios regarding comments, but we can leave them out for now.
    When you reading somebody else's code, you read a code, not the comments, comments (non java docs) should be very short and tell something very accurate, so you'd understand the idea why such approach was chosen, or why there is -45 for a start and not 44 for instance (2 - 4 words), and if possible, better to express that intent with variable name.
     
    Piet Souris
    Rancher
    Posts: 1916
    66
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Many areas in science have special symbols, and lots of formulas using these symbols. So, I can imagine that the use of 'P' and 'T' are very clear to those in the know. You would probably see formulas with these symbols in the specifications. So, why would one choose to use other names for these variables?
     
    Liutauras Vilda
    Marshal
    Posts: 4270
    256
    BSD
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Piet Souris wrote:So, why would one choose to use other names for these variables?
    So the code would be searchable. When you need to look for the particular place in the code, you type in 'pressure' and you find it within seconds, which wouldn't be a case of 'P', unless you rely on method name where this formulae might laying in. After all, if the code is meant to be read only by the specific field experts only, might it is easier the way you say. But personally prefer code more explicit rather than abbreviations and comments along with them.
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    We have already been told there is no formula in this instance.
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    There is simply: No formula.
    All here is related and linked together with Enthalpy gaz features (P,T,V,H,..) As shown below.
    Yes P,T,H are really common symbols used in the industrie, and well known.
    Misunderstanding between Scientist and computer scientist. :-)

    Good point: I fixed my original question of this topic, by re-clarification the issue (thanks to you) :-)


    An operator will measure on different Head-Pump's locations, Pressure(P)/ Temperature(T)/..
    All these Measures (M0,M1,M2) will be entered in the program, and the program has to revert with the corresponding Enthalpy(H0,H1,H2)
    --> Either roughly approximated, but preferable by picking the value with the mouse on "Enthalpy image"   

    To my original question:
    Measure (List) been the "input" of my program, I have to grab information from different other objects (mouse location, enthalpy feature, head-Pump features, ..) to revert with (H0,H1..), and later to compute the performance

    My RAT KINGs: 1
    Where to put (certainly badly named : "updateAllMeasureListElem()") this function with input: M0,M1,M2 and with output estimated H(H0,H1..), and with in the middle,  almost all objects.
    My light has been turn on: In the middle:  with all parameters I need to compute H.., to be passed in the method 
    --> (no inheritance, no association, no static,..)
    ==> Fixed.

    My RAT KINGs 2
    By sense "Measure" is not an "Enthalpy": --> so no Inheritance
    However, to avoid to declare in Enthalpy : public double convT2P(double temp){..}  as static, and then also "all enthalpy instance variables" as static, I have wrongly considered Measure extends of Enthalpy .. :-(
    --> will be changed
    --> By passing Enthaly as parameter to method (dixit RAT KING 1)  
    ==> Fixed.

    My question was a non sense question, because I have tried to fix a Software issue (Static/Non-Static -:: Method/variable) in relation with real word.
    A long topic, with finally a logical answer ...
    Not good to have the head too long in the soft..

    Merci à tous :-)

    Christian

    PS: Relative to UML, my goal is just to have some basics, in order to represent in a nice form the approach of reality
    R22-couleur-A4.png
    [Thumbnail for R22-couleur-A4.png]
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Christian Klugesherz wrote:. . . An operator will measure on different Head-Pump's locations, Pressure(P)/ Temperature(T)/..
    So do you need to model the operator? How many sensors are there per pump? Where are these sensors? Do all these sensors measure temperature and pressure? Or do some measure only temperature or pressure?
    All these Measures (M0,M1,M2) will be entered in the program, and the program has to revert with the corresponding Enthalpy(H0,H1,H2)
    So you mean the program calculates the enthalpy at three locations in the heat pump? We are still not yet at the stage of T₀ or T₁.
    --> Either roughly approximated, but preferable by picking the value with the mouse on "Enthalpy image"
    For the time being, let's say it is roughly approximated. It doesn't really matter what formula you use: guess a formula. We can work out how to get figures from the diagram later.
    To my original question: . . . Where to put (certainly badly named : "updateAllMeasureListElem()") . . .
    How do you know you even need an answer to that question? How do you know you need that List? I am not convinced you need either. Work out the measures for one pump, and when you have that working, you can consider multiple pumps. You need to program one step at a time. You also need to realise that there is an inverse correlation between amount of work done and amount of code written. The more work you do thinking, the less code you will actually write. The less work you do thinking, the more time you will have to write code. So somebody who writes 500 lines in a day has probably done less work than somebody who writes 100 lines.
    . . . My RAT KINGs 2
    By sense "Measure" is not an "Enthalpy": --> so no Inheritance . . .
    Maybe there is such a thing as an enthalpy value, and that can be calculated from temperature and pressure, and the actual enthalpy varies depending on the constituent(s) of the gas. Maybe you can have a calculateEnthalpy() method which takes temperature and pressure as parameters. If that method neither uses nor alters any instance fields, then it is a 1368 in the most dubious classification of methods known to modern science. In which case it might well be static. As an alternative, make an Enthalpy object which takes temperature and pressure in its constructor and has enthalpy as a field. Make all the fields final, and make the class final. Give it getXXX methods (3 of them) and no setXXX methods. If the fields are all double type (or Double), then you will have created an immutable class, which has all sorts of advantages. Override the toString equals and hashCode methods.
    Use a formula to calculate enthalpy. Never mind whether the formula is something ridiculous, even as daft as √(T² + P²) because you will change that later.
    Merci à tous :-)
    Ça ne fait rien
    . . . PS: Relative to UML, my goal is just to have some basics, in order to represent in a nice form the approach of reality
    Your UML for an Enthalpy class will be very simple. And it will not change if you change the method of entering the enthalpy. It will however change if you add a volume field to the Enthalpy objects.
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for all these valuable information Ritchie
    I will take it into account.
    Gentle reminder.
    M0,M1,M2, M3, ... are representing the measure points chosen from enumeration.
    This is the reason why I have to used a List of Measure points

    Now with all these information I will manage.

    Gentle correction:
    Ca ne fait rien "Il n'y a pas de quoi", is most appropriate . :-)

    Christian

     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry for typo.. :.. Is more appropriate :-)
     
    Junilu Lacar
    Sheriff
    Posts: 10929
    158
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Christian Klugesherz wrote:
    So I will try to explain :
    A heat-pump is composed of different elements
    ...
    a list of all these elements
    ...
    Also, I can add, new individual items, and combine later, in order to simulate any Head Pump.
    ...
    (The other name of performance = COP)
    ...
    Finally, to compute performance, == feed Class cCop, you have to pick the Measure values (Pressure, Temperature) on a real Head Pump.

    It has been over twenty years since I last studied Thermodynamics in college on my way to earning an unused BSME so excuse me if I'm a bit rusty on the concepts. I've only brushed up on these things for a few minutes (amazingly, I can still remember a little bit about the Carnot cycle and adiabatic processes) but here's what I think you want to do:

    You want to calculate the Coefficient of Efficiency (COP) of a heat pump system.

    To calculate COP for your overall system, you want to take into account any number of measurements taken at various points in the system. These points correspond to different components of the system, e.g., circulator, compressor, condenser, expansion valve, etc.

    If I'm on track so far, it seems to me that if you want to use object-orientation here, these are the classes I would suggest:

    Does this make sense so far? If it does, then you have a basic framework to expand on. All you have to do is fill in whatever setters you need to specify the measurements you're taking at each component and fill in the calculations for enthalpy and COP.
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Christian Klugesherz wrote:. . . M0,M1,M2, M3, ... are representing the measure points chosen from enumeration.
    You are not ready to think about enumerations (they are not called that; they are enums or enumerated types). Get one measurement point working and then it will be easy to create more, and you can decide whether to put them into Lists, arrays or whatever.
    . . . "Il n'y a pas de quoi" . . .
    Thank you

    The more recent editions of the JLS say enum types.
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    My approach is a bit different.

    I have attached a little part of the uml view of my java code, this gives a good overview. (Reverse engineering uml) :-)

    The place where I set the method is now logical for me.
    I spend a lot of time on that.
    But this helped me to reconsider some points of hierarchy of my classes.

    Again many thanks for your help here

    Christian
    image.jpg
    [Thumbnail for image.jpg]
     
    Junilu Lacar
    Sheriff
    Posts: 10929
    158
    Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Since you asked about complying with object-oriented philosophy, the design you seem to have settled on is not at all object-oriented. Sure, it involves classes, methods, and all the constructs of an object-oriented design but merely having the form of objects doesn't make a design object-oriented.  It's just like strapping some wings on a bicycle and calling it an airplane even if it won't get one inch off the ground from lift. It just simply isn't.

    Here's one giveaway: The MeasureAllPoints class.  First of all, its name is a verb-phrase. Classes should naturally have nouns or noun phrases for their name. Second, it has no state that it uses to dictate its behavior. Instead, it has a single method that gets all the information it needs to do its job from external sources. This is not an object, it's simply a function masquerading behind the accoutrements of a class.

    There are more issues with the design with respect to object-orientation but I won't belabor the point any longer. If you're fine with the way your program is organized and it does what you want it to do, I guess that's good enough. However, you would only be deceiving yourself if you thought for one minute that what you have there is an object-oriented design. The UML diagram actually reminds me of Rene Magritte's The Treachery of Images and the inscription "Ceci n'est pas une pipe"
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Junilu Lacar wrote:Instead, it has a single method that gets all the information it needs to do its job from external sources. This is not an object, it's simply a function masquerading behind the accoutrements of a class.

    This is well understood.
    And this was also the question of this topic. :: "Where to put this Method" ???

    I understood that this was a "non sense question", because, I didn't respect the OO philosophy from the beginning
    But as highlighted, I can live with that :-)
    To go from point A to a point B, you don't necessary need a airplane, bicycle can be an alternative, if, not too faraway :-)

    With that, I consider the topic closed.
    Perhaps, I will deep into OO, one day, and att that momoent, I will certainly consider my programming ugly, but for now, it makes sense to me.

    So, again, many thanks for your sharing. This gave me another view of things, and has open my mind to a new journey (later...:-) )

    Christian
     
     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Last and not the least question:

    If you should suggest an OO programming Java Book.
    Which on would you recommend ?

    I found lot on the NET
    * http://www.cl.cam.ac.uk/teaching/0910/OOProg/OOP.pdf
    * http://fms.uofk.edu/multisites/UofK_fms/images/pdf/C._Thomas_Wu_An_Introduction_to_Object-Oriented_BookFi.org.pdf
    * http://zums.ac.ir/files/research/site/ebooks/it-programming/object-oriented-programming-using-java.pdf
    * ..

    Merci




     
    Christian Klugesherz
    Ranch Hand
    Posts: 103
    3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Pending your recommendation to OO literature.

    I just have decided to modify the empty constructor class, with a much more OO oriented Class view
    (even if not purist in the whole OO approach)

    Conclusion:
    Solution retained, is the one which was highlighted above as Solution 3.
    Class named: "MeasureCollection"
    Because this class will dissect all Measured elements between them, and to re-affect the correct value to each single element, and add computation of Enthalpy.
    This will be my last word in that Topic relative to the solution chosen :-)
     
    Capture.PNG
    [Thumbnail for Capture.PNG]
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Afraid you have been unlucky there. I think the only thing you have found there which is any good is the book by Wu, but that appears to be an old edition. The book linked on the Irish University website isn't bad, but the history chapter is full of errors and incomplete, so I didn't read any more. The only book from the Cambridge document I would recommend is that by Eckel, though Deitel (“early objects” edition) does teach object orientation (=OO). It used to be possible to download Eckel free of charge as a .pdf, but that is an old edition pre‑Java5. Try searching mindprod.com in the first instance.

    Lots of books write lots about UML, but UML isn't OO. It is, as Junilu has told you, a notation, which allows you to see how you have used OO in your programming. Or, in this case, how you haven't used OO.

    I think if you are asking where to put this method, you have missed the earlier question, which is, “Do I want this method?” If you have a simple function, is that OO? Something like a logarithm might be OOOr it might be implemented as a functionThat is partially because logarithm can be implemented as a pure function. You pass a value and get a value back. If I calculate log(10) today and get 1.0 returned, I shall still get 1.0 if I try it again tomorrow. So I don't need an object to calculate a logarithm; it can be done independently of any instance fields' values. Maybe the design of the Math class is partially like that for historical reasons, that in older languages there were pure functions called log() and exp() not belonging to any classes. Maybe if Java® were being designed today they would design it like my MyNumber class; nobody knows.

    I still think you need to go back to your original description of the heat pump. Maybe you have sensor objects and each sensor has temperature and pressure fields. Maybe you have circuit segment objects each with a start temperature and an end temperature. In which case the start temperature of one segment is equal to the end temperature of the preceding segment. Similarly pressure. That looks like OO to me. I am sure Junilu will suggest refinements and improvements to that design. Maybe you want a pump which “IS‑A” circuit segment. Maybe an evaporation coil is a circuit segment similarly. That sounds OO, too. Maybe you want several sensor objects, and maybe you can get away without having the sensors separate. Maybe it is better to have sensors and each segment can have a reference to the sensor at its start and a reference to the sensor at its end. That would also be OO.
    But I am sure you don't want that enumerated type in that form. You are simply going back to the old design which we have already said isn't OO.
     
    Campbell Ritchie
    Marshal
    Posts: 54909
    155
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have read a bit more of that book on the Irish link, and it seems to get better as you go. Chapter 2 looks quite good.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!