Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
7 Views

How use different classes as one property of a class

Jump to solution

Short version:

We have class element with property of material

We have class steel and class concrete as materials.

I want that the element be able to receive either steel class or concrete class as element%material property.

What approach should I use to make this possible?

____________________________________________________________________________________

Detailed version:

Say we have a Hex element.

Elements can receive one material from various types as property say Concrete or Steel.

All materials have some common properties for example modulus of elasticity.

They also have some common methods but the way that the methods do a calculation is different for each material.

For example:

Concrete%Yield() will do calculations and return a value different from how Steel%Yield() would, but both materials have Yield() method which is accessed from element class.

Now I want my Hex element have a material property.

I created an abstract class material with property of material%Elastic_modulus and a differed method of material%Yield().

I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313:

The TYPE(derived-type-spec) shall not specify an abstract type.

So if this is not allowed how can I have a class element which can receive either concrete or steel class as material property?

____________________________________________________________________________________

I would appreciate your help.

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor III
7 Views

SPMay wrote:

.. I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313: ..

Use CLASS statement instead of TYPE but with a suitable attribute specifier, preferably ALLOCATABLE:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-class

View solution in original post

0 Kudos
1 Reply
Highlighted
Valued Contributor III
8 Views

SPMay wrote:

.. I want to create Hex class with abstract class of material as a property so I can use steel%material or concrete%material to assign my material to element. But I receive compiler error 8313: ..

Use CLASS statement instead of TYPE but with a suitable attribute specifier, preferably ALLOCATABLE:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-class

View solution in original post

0 Kudos