Interfaces
How to count the number of elements in the preceding organization(s) ?
- To enforce subclasses to overload a set of operations, an operation can be declared as
abstract
(then have 'no code'):
public abstract class Element { public abstract int count(); }
public abstract class NamedElement extends Element { ... }
public class Person extends NamedElement {
public int count() { return 1; } // overloading/implementation
...
}
public class Group extends NamedElement {
public int count() {
int res = 1;
for(int i=0; i<size;i++)
res += elements[i].count();
return res;
}
...
}
Thus, sport.count();
will return 7 = 1 group + 2 subgroups + 2 persons/subgroup(x2).
UML/SysML class diagram
10 - 14Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented