0

Title sucks, I know, but I'm having trouble describing my question.

Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each of which are classes of their own that load a deep learning model for vision, then store the data they see.

My question is this: should I merely have a class attribute for Three_Eyed_Robot called red_data and instantiate the Red_Eye class in a method that sets red_data, or instead have Red_Eye be an attribute of Three_Eye_Robot and use the data by calling Three_Eyed_Robot.Red_Eye.red_data?

Edit: clearer wording.

1
  • Depends if Three_Eyed_Robot ever combine the colors and exposes something more useful, or is simply a facade.
    – S.D.
    Aug 18, 2022 at 13:40

1 Answer 1

2

Design (at least in OO) always depends on behavior.

So it depends on what the Three_Eyed_Robot does. I.e. what methods it has and what it needs to fulfill those methods. If it only needs the "data", then yes, it should only have the data.

In general, you should try to avoid getting data from other objects. It makes the design less maintainable, since things get used elsewhere makes seeing what happens harder.

1
  • I see what you are saying. Three_Eyed_Robot really only needs the output from the eyes, so maybe the eyes should be instantiated in methods that output the data and deleted at the end of them to keep things tidy.
    – Ryan Folks
    Aug 17, 2022 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.