Thread Subject: Object's dependent properties

Subject: Object's dependent properties

From: crc

Date: 18 Aug, 2011 15:25:11

Message: 1 of 7

I have two objects. Object1 has a property obj2 which is of type object2. They both have a property called failed. I would like the failed property of object2 to be dependent on the failed property of object1.

So far I have passed object1 into the constructor of object2 and store it in a property called "owner" so that object2 can see object1's failed property and copy it. I think this is the wrong way to do this. It causes object1 to be a property of object2 and vice-versa (making an infinite children recursion problem). I need object2 as a property of object1 and object2.failed to mimic object1.failed.

The two object's class definition examples I am working with:

classdef object1 < handle
    properties
        failed = false;
        obj2
    end
    
    methods
        function obj = object1
            obj.obj2 = object2(obj);
        end
    end
end


classdef object2 < handle
    properties
        failed
        owner
    end
    
    methods
        function obj = object2(owner)
            obj.owner = owner;
        end
        
        function value = get.failed(obj)
            obj1 = obj.owner;
            value = obj1.failed;
        end
    end
end

Subject: Object's dependent properties

From: per isakson

Date: 20 Aug, 2011 18:51:08

Message: 2 of 7

"crc" wrote in message <j2jasn$hig$1@newscl01ah.mathworks.com>...
> I have two objects. Object1 has a property obj2 which is of type object2. They both have a property called failed. I would like the failed property of object2 to be dependent on the failed property of object1.
<snip>

What do mean with "to be dependent on". Exactly, what behavior do you want?

Subject: Object's dependent properties

From: crc

Date: 23 Aug, 2011 06:25:10

Message: 3 of 7

In this specific case (for these example classes of object1 and object 2) I would like object2.failed to mirror object1.failed. In a more general sense, I was wondering what the commonly accepted way to make object1's properties accessible to object2 for use. The problem I am running into with these example classes is that passing object1 into the constructor of object2 and storing it into owner, is setting object1 as a child of object2. This creates a parent child loop that would go into infinite recursion if I were to look at nested properties of the classes with a property inspector.

For now I have resorted to using the set.failed method in object1 to set the object2.failed property. Then there is no need to store a variable called owner and cause recursion.

But I would still like to know people's thoughts about making object1's properties accessible to object2.

Subject: Object's dependent properties

From: Steven_Lord

Date: 23 Aug, 2011 13:09:51

Message: 4 of 7



"crc " <camroncall@gmail.cam> wrote in message
news:j2vh45$jpc$1@newscl01ah.mathworks.com...
> In this specific case (for these example classes of object1 and object 2)
> I would like object2.failed to mirror object1.failed. In a more general
> sense, I was wondering what the commonly accepted way to make object1's
> properties accessible to object2 for use. The problem I am running into
> with these example classes is that passing object1 into the constructor of
> object2 and storing it into owner, is setting object1 as a child of
> object2. This creates a parent child loop that would go into infinite
> recursion if I were to look at nested properties of the classes with a
> property inspector.
>
> For now I have resorted to using the set.failed method in object1 to set
> the object2.failed property. Then there is no need to store a variable
> called owner and cause recursion.
>
> But I would still like to know people's thoughts about making object1's
> properties accessible to object2.

Define property access methods for object2.failed that set/get object1's
failed property and make it Dependent.

http://www.mathworks.com/help/techdoc/matlab_oop/brgsek9-1.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Object's dependent properties

From: crc

Date: 23 Aug, 2011 17:55:26

Message: 5 of 7

Steve - thanks for your input. That is what I originally wanted to do. However, I don't know how to access the properties of object1 from within a method of object2 without passing object1 into the constructor of object2 and storing it as a property of object2. I would love for the object2's set.failed method to get the value of object1's failed property.

Subject: Object's dependent properties

From: crc

Date: 23 Aug, 2011 18:09:10

Message: 6 of 7

Sorry - typo in the last sentence. --> I would love for object2's get.failed method to have access to the value of object1's failed property.

Subject: Object's dependent properties

From: Steven_Lord

Date: 23 Aug, 2011 18:48:28

Message: 7 of 7



"crc " <camroncall@gmail.cam> wrote in message
news:j30pie$qrn$1@newscl01ah.mathworks.com...
> Steve - thanks for your input. That is what I originally wanted to do.
> However, I don't know how to access the properties of object1 from within
> a method of object2 without passing object1 into the constructor of
> object2 and storing it as a property of object2. I would love for the
> object2's set.failed method to get the value of object1's failed property.

There needs to be SOME relationship between object2 and object1. How should
object2 "know about" the instance of object1 whose property you want
object2's property to depend upon? Should object1 trigger an event for which
object2 listens?

http://www.mathworks.com/help/techdoc/matlab_oop/bqvggvt.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Everyone's Tags:

oop

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
oop per isakson 20 Aug, 2011 14:41:06
rssFeed for this Thread

Contact us at files@mathworks.com