Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  delnan May 23 '12 at 12:28
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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