Re: java class hierarchy




"Thomas" <arabel9@xxxxx> wrote in message
news:f7td3a$lcs$2@xxxxxxxxxxxxxxxxxx
Hello I 'm writing a simple ONP expression evaluator with functions in
java.
The constrains about the class hierarchy are like that :

abstract Symbol implements Evaluate (which contains
method evaluate)
/ \
/ \
/ \
abstract Function abstract Operand
/ | \ / |
\
Plus Minus Ln Literal Const Variable

The evaluation process should be : after parsing the input we put all
those
object into the queue. By reading the queue and using the stack to keep
the
temporary values (both of them I implement on my own) i have to do like
that
:
1) if it is an Operand put in on stack
2) if it is an function and
2)a we have enought arguments on stack we valuate the function
2)b we throw exepction
(i can distinguish beetwen this two types and here i don't need help,
because of the diffrent number of arguments they take and exceptions)

In the main loop I have to keep the refrence to the object taken from
FIFO,
and here is the problem : what type of refrence it should be ? Not a
symbol
because it is abstract, but it implements the Evaluate interface. I
confused. Any suggestions, please ?

There's no hard and fast rule, but as a rule of thumb, in this
situation you would use the least general type which is a supertype of all
the possible types you might get from your FIFO queue.

The issue is that you will probably want to do something with each
element you take out of the queue. Usually, to "do something" involves
invoking a method. Which means the method you want to invoke must be part
of the type of the reference (or you could use casting, but that gets
messy).

So say if you wanted to call the .doSomething() method on each
element, the type of the reference would need to be such that the
..doSomething() method is defined on that type. If the .doSomething()
method is defined in Symbol, then use Symbol as the type of the reference.
If the method is defined in Evaluate, then use Evaluate. If it's defined
in both, then it doesn't matter too much which one you use.

- Oliver


.



Relevant Pages

  • [PATCH 05/19] io-controller: Common hierarchical fair queuing code in elevaotor layer
    ... Requests keep a reference on ioq and ioq keeps keep a reference ... So the queue can be freed. ... Cgroup deletion path holds iocg->lock and removes iog entry ...
    (Linux-Kernel)
  • [PATCH 05/20] io-controller: Common hierarchical fair queuing code in elevaotor layer
    ... Requests keep a reference on ioq and ioq keeps keep a reference ... So the queue can be freed. ... Cgroup deletion path holds iocg->lock and removes iog entry ...
    (Linux-Kernel)
  • [PATCH 09/25] io-controller: Common hierarchical fair queuing code in elevaotor layer
    ... Requests keep a reference on ioq and ioq keeps keep a reference ... So the queue can be freed. ... Cgroup deletion path holds iocg->lock and removes iog entry ... struct io_entity *entity) ...
    (Linux-Kernel)
  • Re: 7.0 wishlist?
    ... doing it at compile time runs into the problems shown. ... At least an NPE in seemingly-null-safe could would then be prima facie evidence of thread-unsafety in the null's source chain, and with a runtime check on the reference assignment the NPE will occur in one of blocks that participated in a race condition instead of somewhere random later on. ... void method ... For that, I have the thread hold the queue in a WeakReferenceand if the removemethod hits the timeout, it sleeps for a while holding no other references to the queue. ...
    (comp.lang.java.programmer)
  • Re: simple static question
    ... reference to it's static queue, will the "lost" reference to class A I ... /do/ make use of classloaders. ...
    (comp.lang.java.programmer)