Defining class methods in the "deeper levels" of a class
조회 수: 2 (최근 30일)
이전 댓글 표시
I would like to be able to define class A in such a way that the command A=A.B.Method will be able to modify properties A.PropA and A.B.PropB. The closest I've gotten is by defining B2 as it's own class, and defining a property of A as "B=B2", but I have to use the command A.B=A.B.Method, and I'm not able to modify properties of A. It seems like I may be able to accomplish this or something similar using superclasses and/or object handles or maybe anonymous function handles, but I'm new to defining MATLAB classes and to OOP in general so I can't quite figure it out.
댓글 수: 0
답변 (1개)
Jeff Miller
2020년 11월 27일
A toy example might be needed to make it clearer what you are after, but I guess you want a class A which has as two of its properties a variable PropA and an object B.
If that's right, then it wouldn't be good OOP to have a call to B modify PropA, even if that is possible.
It would be better to make PropA a function (of A) that simply calls the function of B (call it "GiveMePropA") that returns the value you want PropA to have. If GiveMePropA is expensive to compute, you might just have A call it whenever needed and store its value.
댓글 수: 3
Jeff Miller
2020년 11월 28일
Kowabunga that sounds complicated--certainly well beyond any OOP I've done. Is your idea to have an abstract Ledger class and then descend Bills, Loans, etc from that, so that the Budget class is just a list of Ledger objects?
참고 항목
카테고리
Help Center 및 File Exchange에서 Software Development Tools에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!