"- In the first part of the diagram you can find the class Name, in the second part the attributes followed by the methods.\n",
"- The **minus** in front of the attribute names means that these are **private** attributes: They are not visible outside the class.\n",
"- The **plus** in front of the method names means that these are **public** methods: they are visible outside the class."
]
},
{
"cell_type": "markdown",
"id": "177180eb-a57c-4a9f-bf1e-228f05ebd93f",
"metadata": {},
"source": [
"### Private attributes in Python\n",
"- Private attributes that cannot be accessed except from inside an object don’t exist!\n",
"- But there is a convention for marking attribute as private by prefixing it with an single underscore.\n",
"- Attributes without an underscore are public.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3c98e247-a2f2-4ead-9ab7-bf128aed8dc4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mark\n",
"46\n"
]
}
],
"source": [
"class Student(object):\n",
" # constructor\n",
" def __init__(self, name, age):\n",
" self.name = name # public attribute\n",
" self._age = age # convention for marking private attribute\n",
" # get attribute age\n",
" def getAge(self):\n",
" return self._age\n",
"\n",
"s = Student(\"Mark\",\"46\")\n",
"print(s.name) # public attribute\n",
"print(s._age) # „private“ attribute"
]
},
{
"cell_type": "markdown",
"id": "9eef4cf2-8506-4762-a269-0cd4e29bec56",
"metadata": {},
"source": [
"### Inheritance\n",
"- If classes have something in common, you can extract the common aspects of class C1 and C2 and create a class C (superclass, baseclass) that implements these aspects. \n",
"- C1 and C2 are smaller subclasses (or derived classes), containing only unique attributes / methods.\n",
"\n",
"TO DO: IMAGE\n",
"\n",
"Here is an example about inheritance in Python:\n",
"- The class GraduateStudent inherits its behaviour from the class Student\n",
"- The common attributes are stored in the Superclass Student, the special attribute undergradMajor is stored in the derived class.\n"
]
},
{
"cell_type": "markdown",
"id": "645b5011-21c5-479e-811a-54a0f635bb40",
"metadata": {},
"source": [
"# OOP in Earth System Sciences\n",
"How does Object Oriented Programming look like in ESS? Here is an example that uses a class diagram to show how the framework works. You can see easily how you can add your own class by looking at the diagram, and that is the **big advantage of UML and the object oriented design**!\n",
"\n",
"### CHEPROO, Object-Oriented tool specialized in complex geochemical processes:\n",
"S. A. Bea; J. Carrera; C. Ayora; F. Batlle; M. W. Saaltink, CHEPROO: A Fortran 90 object-oriented module to solve chemical processes in Earth Science models, http://doi.org/10.1016/j.cageo.2008.08.010\n",
- If classes have something in common, you can extract the common aspects of class C1 and C2 and create a class C (superclass, baseclass) that implements these aspects.
- C1 and C2 are smaller subclasses (or derived classes), containing only unique attributes / methods.
How does Object Oriented Programming look like in ESS? Here is an example that uses a class diagram to show how the framework works. You can see easily how you can add your own class by looking at the diagram, and that is the **big advantage of UML and the object oriented design**!
### CHEPROO, Object-Oriented tool specialized in complex geochemical processes:
S. A. Bea; J. Carrera; C. Ayora; F. Batlle; M. W. Saaltink, CHEPROO: A Fortran 90 object-oriented module to solve chemical processes in Earth Science models, http://doi.org/10.1016/j.cageo.2008.08.010