actually I wanted to know how to display list or names of subclass which belongs to particular superclass in python. I have 1 superclass named "company" and 2 subclasses "employees" and "customers".
class company:
def-------
----------
print('subclass of company are %d',(?))
class customers(company):
def--------
-----------
class employees(company):
def---------
------------
what to use in place of ? mark to display subclass of superclass "company"
Related
I wish to assert a relationship between an individual and a class. E.g I have "John" in class "Smith", and I would like to have the assertion "Works_In" to class "Tesco" so it would read "John" WorksIn "Tesco" within protégé.
I tried using the object property assertions but that only lets me do individual to individual assertions, and when I use the data property assertions, the reasoner doesn't work with it.
I am trying to understand how Cardinalities and Relationships work with Generalization in simple UML class diagrams. I have this simple example here:
A Player owns exactly 9 Fields, but the distribution of them is irrelevant (i.e. 5 Endfields, 4 Startfields or 1 Endfield and 8 Startfields). The Field class is abstract. If i model this problem as seen above, would a Player have 9 Fields from each type? If so, how do i model this correctly?
If i model this problem as seen above, would a Player have 9 Fields from each type?
not at the same time. In your model a Player is associated to 9 Fields, knowing each Field is a Endfield or-exclusive a Startfield (supposing there are no other classes inheriting Field)
A given instance of Field cannot be both a Endfield and a Startfield, else that means Fields inherits both Startfield and Endfield (but the inheritances are in the opposite direction)
The corresponding classes in Java from your model can be :
abstract class Field { .... }
class Startfield extends Field { ... }
class Endfield extends Field { .. }
so a Player can be in relation with 9 Endfields, or-exclusive 8 Endfields and 1 Startfield, or-exclusive 7 Endfields and 2 Startfield, ..., or-exclusive 1 Endfield and 8 Startfields, or-exclusive 9 Startfields
If you want a Player has 9 Startfields and 9 EndFields your model can be :
[edit]
However if you extend your model adding an other class inheriting Startfield and Endtfield like :
in case a Player is associated to 9 Bothfields in a way it is also associated with 9 Startfield and 9 Endtfield
The multiplicity (9) of the relation concerns Field, for the inheriting classes that depends as you can see
Your model does correctly express your intended meaning except that you need to add a disjointness constraint to your Endfield-Startfield segmentation (called "generalization set" in UML jargon) for making sure that a field cannot be both an end field and a start field.
As of UML 2.5, segmentations are overlapping (and incomplete) by default. See also the (always excellent) explanations on uml-diagrams.org, which shows how to draw the disjointness constraint.
My model is as follows
abstract concept Address {
o String street
o String zip
o String city
o String country
}
participant Actor identified by userId {
o String userId
o String firstName
o String name
o Address address
}
When I POST a new Actor in composer rest server, I get the following error
"Cannot instantiate Abstract Type Address in namespace
io.mydomain.myapp",
What am I missing out on here ?
Abstract types are not meant to be instantiated so no wonder that it can't be created.
Read: https://hyperledger.github.io/composer/latest/reference/cto_language
Specifically this quote is of interest:
An optional 'abstract' declaration, to indicate that this type cannot
be created. Abstract resources can be used as a basis for other
classes to extend. Extensions of abstract classes do not inherit the
abstract status. For example, the asset Vehicle defined above should
never be created, as there should be more specific asset classes
defined to extend it.
Consider the Concepts subheading of the docs.
TL;DR: Read the documentation.
See the following code:
class Car implements GroovyInterceptable{}
car=new Car()
Car.metaClass.hello={println "class Car:hello"}
car.metaClass==Car.metaClass
the result is:
false
So my question is: What's the difference between car.metaClass and Car.metaClass? I did some searching, but no result. Could anyone help on this?
car.metaClass is applicable to the object called car. You may modifiy it, but it will not be visible to other Car objects
When you modify Car.metaClass, that is will be applicable to all objects of Car.class (created after this new meta modification)
class Car implements GroovyInterceptable{}
car=new Car()
Car.metaClass.accelerate {->println "Factory tested. Safe acceleration"}
car.metaClass.accelerate {->println "Owner modified : Random acceleration"}
def anotherCar= new Car();
anotherCar.accelerate()
car.accelerate()
Output
Factory tested. Safe acceleration
Owner modified : Random acceleration
public class ABC
{
}
public class DEF : ABC
{
}
public class Class1
{
ABC abc = new DEF(); //No error
DEF def = new ABC(); //Compile time error
}
Can anyone explain to me this scenario.
and under what circumstances we might use it.
Its because as per the OOD rule you can assign child to parent but you cannot assign parent to child.
//this possible as you re assigning child to parent
ABC abc = new DEF(); //No error
//this is illegal as you are trying to assign child to parent directly
DEF def = new ABC(); //Compile time error
Reconsider your design again or if you want to convert parent object to child than you need method for that conversion directly its not possible to do it as per OOD rules.
Consider real time example relation of Customer and RetailCustomer or Corporatecustomer of bank. Where you can easily say RetailCustomer or CorporateCustomer is Customer, but you cannot say Customer is RetailCustomer or CorporateCustomer because customer can be of any type.
Same goes for relation between Parent Shape Class and Child Rectangle,Circle etc. class.
This is called as Ploymorphism .
As explained in MSDN
At run time, objects of a derived class may be treated as objects of a
base class in places such as method parameters and collections or
arrays. When this occurs, the object's declared type is no longer
identical to its run-time type.
Base classes may define and implement virtual methods, and derived
classes can override them, which means they provide their own
definition and implementation. At run-time, when client code calls the
method, the CLR looks up the run-time type of the object, and invokes
that override of the virtual method. Thus in your source code you can
call a method on a base class, and cause a derived class's version of
the method to be executed.
The answer of for this question is best explained here MSDN Polymorphism
Let's say ABC is Person, while DEF is Student (which is a subclass of Person). You can always treat a Student as a Person, so the assignment to abc (of type Person) of a Student is correct, but you cannot treat a generic Person as Student, so the assignment to def is wrong (for instance, you cannot get the student number of a person which is not a student)