0

In OOP, it seems that if an object cross-references another object in its property, ultimately, if such objects are used a lot, the software at the end will be slow because of this.

Is this true? If yes, can we intentionally not do this by getting things done?

  • What language? In JavaScript it could get costly depending on circumstances or core object used. I wouldn't expect a significant cost in pre-compiled languages but if most objects are tangled webs of calls to other objects, that may be a symptom of an architectural problem. – Erik Reppen May 23 '12 at 4:08
  • What the heck makes you suspect this? – user7043 May 23 '12 at 12:28
3

I'm not entirely sure I understand the question, but if an object contains another object by reference, then the cost of this is a pointer dereference every time you use the contained object. That's a trivial cost.

3

The performance difference is minor compared to having cleaner and more maintainable code. Take a look at the provided API's for your language and see how common it is for objects to be nested. Classes that only deal with primitives are probably in the minority.

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.