Within object oriented paradigm, can object property become a new object ?

For example, the sun (the star) has the properties name, temperature, mass, diameter, etc. And one can create methods to do some calculations on these properties.

The question is: Can, for example, the mass as property become an object of the same kind (can it inherit properties from the object 'sun') with eventually some other properties?

New contributor
benlala is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

put on hold as unclear what you're asking by Jörg W Mittag, John Wu, gnat, Bart van Ingen Schenau, amon Oct 11 at 7:04

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • A property in OOP is typically some combination of backing field (instance variable) and a getter (and/or setter) method. – Erik Eidt Oct 10 at 22:56
  • 2
    We could speak then to the instance variable being/becoming a new object, and that depends a lot on the language. Java and C# have variables: local variables and instance variables (fields) -- however, when these variables have an Object type, they are really just references to objects (that are, logically speaking) in the heap. C++ allows local and instance variables to be objects themselves, or references to objects. – Erik Eidt Oct 10 at 22:56
  • We could then also speak to the methods, and some languages allow using methods as a first class type, this goes to higher order functions. – Erik Eidt Oct 10 at 22:56
  • 1
    @benlala It's hard to understand what you have in mind. Could you edit your question and add more context, please? Code, or a class diagram, or an instance diaram would help here. – Nick Alexeev Oct 10 at 22:57
  • I am not sure what the OP is asking but this link may be relevant. – John Wu Oct 10 at 23:28

In many object oriented languages properties are not objects themselves. I tend to understand properties belonging to classes and property values belonging to instances. Of course those values may be objects again (or primitive, if the language distinguishes those).

However, by using reflection properties may become accessible through objects of types called PropertyDescriptor, PropertyInfo, Field and so on. Usually such objects offer methods like SetValue and GetValue. Oftenly those accessor objects are not bound to a particular fixed target instance but they expect it to be passed as parameter: myClassProperty.getValue(myClassInstance) and myClassProperty.setValue(myClassInstance, newValue)

  • thank you for your reply. I give you some explanations about my question: an object has properties that can be inherited by other objects, but the question is this: is it possible for one of the properties to become an object that will eventually have its own properties? Is it clear enough? – benlala Oct 12 at 0:33
  • Okay, we still have to clarify some aspects. What do you mean by "become"? Let's assume we have some class A with a public property x of type X and a class B which inherits from A. If you define "property" as a field, then B inherits it and its type is X too. If you define "property" as two public methods (getter and setter), then (by Livkov's substitution principle) you may override the getter and let it return a subtype of X. On the other hand any override if the setter would need to have the same or a super type of X for its parameter. – Hero Wanders Oct 12 at 7:17
  • Continuing my previous comment: therefore assuming your method-defined properties are read only (only getter, no public setter), B may indeed have a property x of type Y where Y inherits from X. This is just return type covariance. Now it depends what you choose for X and Y. For example in many languages it would not be valid to use X = int (numbers) and Y = Z where Z is some custom class with arbitrary properties as usually Z does not inherit from int. It depends on the language's type system which types inherit from other types. – Hero Wanders Oct 12 at 7:25
  • Other explanations: – benlala Oct 12 at 18:18

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