oop - Scala Function vs Class Dichotomy -


I've just started learning Scala I am resting with OO design to a great extent, and with less functional programming; However, I am programming for a long time that the FP is not completely unnatural for me. From the first day of my Scala adventure, I had this, we would say, unease with clear sway which is running between Oh and FP Obviously, no one can go either way or in all other ways, my first trend was to look at the sections as packages which hold the function together which I want to pass, which are the scales toward the working side. I think there should be a better way of balancing this act. I am also not sure how to move forward with some familiar situations under this scenario. For example, if I had the following (artificial) class:

  class ValueGenerator {def value () = {"1"} def value (line: string) = {line}} < / Code>  

In OO programming, I will call value with the appropriate signature to get the code needed for it. The methods are the same sign, because they correspond to similar rational tasks. In the OO, I used to pass the object reference, and by which method the value valueGenerator gets, it will call the correct value depending on the condition. As far as I can see, at least this is my tendency, in Scala it is to go around the ideal method. But in this case, though in the same way, in the same way, they do not have the same signature, so can not be replaced for each other (or are they?) In other words, regardless of the signature of the sender method function Can the function be sent without doing? It seems impossible because the receiver will not be told how to implement it. What is the correct action in this situation or do they go with their intestines? When does OB versus FB come?

As a side note, it was interesting to see that a friend of mine who was learning Scala, had the exact idea (or lack thereof) on this issue.

They do not have the same signature, and generally you want those methods which are different - There is no identical signature to be different names. Overloading buys you very little and spends you a lot (i.e., type estimation and built-in resolution).

He said, they can not be replaced for one another because they do not have the same type. If you convert these methods to functions, then there would be one type Function0 [string] , and the second would type Function1 [String, String] .

Comments