bad style. this code would invalidate all of your constructors if you
change the number of fields in STfields. and changing the API for an entire
class of objects is generally frowned upon by your users

if you expect to be sharing several common fields, the suggestion has been
to create a type that aggregates them together and use the has-a rather
than isa relationship

type STfields()
a::Int
b::String
end
abstract ST
type MyST <: ST
  common::STfields
  c
  d
end


On Fri, Jun 20, 2014 at 9:03 AM, Mauro <mauro...@runbox.com> wrote:

> What about using a macro to define the common types? That would avoid the
> problem of having to visit each subtype declaration when more common fields
> are added. Is that good or bad style?
>
> julia> macro STfields()
>        quote
>        a::Int
>        b::String
>        end
>        end
>
> julia> abstract ST
>
> julia> type MyST <: ST
>        @STfields
>        c
>        d
>        end
>
> julia> names(MyST)
> 4-element Array{Symbol,1}:
>  :a
>  :b
>  :c
>  :d
>
>

Reply via email to