Please Help Me About Sub and Super Classes
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am trying to learn classes in Matlab here is a basic question. How can I write two classes A and B in order to represent following structur?
My first class is A and second class is B. Let A has two property as p and q and B has also two property as m and n. Moreover, one of class is subclasses of other.
A.p=1;
A.q=2;
B.m=3;
B.n=4;
A.B=B; %Minor question :) which one is a subclass A or B?
%Hence
A.B.m %should be 3
A.B.n %should be 4
3 commentaires
Volkan Kandemir
le 16 Mai 2013
Modifié(e) : Volkan Kandemir
le 16 Mai 2013
per isakson
le 16 Mai 2013
You have defined A as a subclass of B and the result you see is as documented, i.e. what you should expect.
Réponse acceptée
per isakson
le 16 Mai 2013
Modifié(e) : per isakson
le 16 Mai 2013
It is a convention to use upper case for the first letter in a class name and lower case for instancies/objects
Try
>> a = A();
>> a.b.m
ans =
3
where
classdef A
properties
p = 1;
q = 2;
b = B;
end
end
and
classdef B
properties
m = 3;
n = 4;
end
end
.
One more example
>> A.B.m
ans =
3
where
classdef A
properties ( Constant )
p = 1;
q = 2;
B = B();
end
end
and
classdef B
properties ( Constant )
m = 3;
n = 4;
end
end
However, I don't think this is what you really ask for.
2 commentaires
per isakson
le 17 Mai 2013
There is very little on naming conventions in the Matlab documentation.
google for "object oriented programming naming conventions"
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Construct and Work with Object Arrays dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!