I was waiting for someone others to comment on it. But since no one did it,
I'll try it.

Your solution is just fine for personal use. But imagine that you are
making an application working on ObjectiveFunction. For your clients to
profit from your application, they should inherit a concrete type from your
abstract ObjectiveFunction. However, ObjectiveFunction gives no information
about how to construct a concrete subtype. All your clients know is that
they can use a "fancy call". All in all, for your clients, they have to
have knowledge of inheritance (a beginner won't be able to do it) and
perfect information of interface (should provide a detailed manual).

Instead, my solution is more direct and flexible, Everyone looking into the
definition knows that all it needs is two functions. I can further use
constructor to regulate the initialization. Moreover, my object can work
with your type: `myObjectiveFunction.f = yourObjectiveFunction` and
`myObjectiveFunction.g = @D yourObjectiveFunction`.

On Wed, Nov 18, 2015 at 3:22 PM, Christoph Ortner <
[email protected]> wrote:

>
>
> On Wednesday, 18 November 2015 09:16:30 UTC-5, Sisyphuss wrote:
>>
>>
>>
>> On Wednesday, November 18, 2015 at 2:53:02 PM UTC+1, Christoph Ortner
>> wrote:
>>>
>>> Not quite answering your question, but here is how I like to do this:
>>>
>>> abstract ObjectiveFunction
>>> type MyOF <: ObjectiveFunction
>>>    params
>>> end
>>>
>>> function evaluate(f::ObjectiveFunction, x)
>>>      . ..
>>> end
>>>
>>> Here, I think it should be `evaluate(f::MyOF,x)`
>>
>
> yes - sorry.
>

Reply via email to