Skip to content

Unusual constructor design #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JeffFessler opened this issue Jul 4, 2022 · 3 comments
Closed

Unusual constructor design #30

JeffFessler opened this issue Jul 4, 2022 · 3 comments

Comments

@JeffFessler
Copy link
Member

See:
#29 (comment)

@johnnychen94
Copy link

It seems to me that the Gauss3(...) function is made for two purposes: 1) interpreting convenient input types (cx, cy, cz, wx, wy, wz, Φ, Θ, value) to a more structural one (center, radii, angle, v), and 2) create an AbstractObject type that wraps it (IIUC this is because AbstractObject and AbstractShape shares different type hierarchy).

How about separating these coupled functionalities apart via:

# type annotations are skipped for illustration purpose
struct Gauss3 <: AbstractShape3
    center
    radii
    angle
    v
end

struct Object{S, D, ...} <: AbstractObject
    # no `shape` field
    center
    radii
    angle
    v
    param
end
Object(shape, params) = Object{typeof(shape)}(shape.center, shape.radii, shape.angle, shape.v, param)

I guess the reason you want to make Gauss3 a type with empty fields is because you don't want to store the same information in both ob.shape and ob. This can be done equivalently to only store the type information in type parameters S so that functions can still dispatch on types S.

But another question is, how necessary it is to store information in ob.center and not ob.shape.center?

@JeffFessler
Copy link
Member Author

Thanks for the input! I would prefer to avoid the nesting of ob.shape.center and I'd also prefer to avoid the repetition of many shapes all having the same args (center, radii, angle, v) so after I finish up some other work I will revisit this and probably adopt your initial suggestion of lower case gauss3 for the constructors, perhaps as wrappers around something like your suggestion of
Object{typeof(shape)}(shape.center, shape.radii, shape.angle, shape.v, param).
I'll ping you eventually when I make a PR related to this.

@JeffFessler
Copy link
Member Author

closed by #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants