scala - computing base class parameters from derived class -


I have the following problem (programming language: scala): A derived class D with base length The parameter should be calculated from its parameters:

  class D (A: IIT, B: IT) B (F (A, B)) {...}  

Now I have 3 possibilities:

(A) Put the body of F (A, B) in the manufacturer of straight B: B ({...})

<

(C) Define F as member function of D Which has to be stable

(A) looks very strange, is this approach too legal? what will you do?

I am asking the question because I am starting with Scala and have not actually been installed in our organization yet, so I can only use it at home.

> Thanks for all the replies.

Apply Apply method in the appropriate object to the constructor parameter in the companion object. Change from

  object B {def f (a: int) = a def apply (a: int, b: int) = new b (f (a), f (b) )}  

If you always need to change constructor arguments then think about the accuracy of your API. I think this code improves from code review.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -