01_Defining_Data_and_Functionality.4

01_Defining_Data_and_Functionality.4 - VDM Class Outline...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
TIVDM1 Defining Data and Functionality 1 Defining Data and Functionality Peter Gorm Larsen TIVDM1 Defining Data and Functionality 2 VDM++ Class Outline class class <class-name> <class-name> end end <class-name> <class-name> instance variables ... types types values functions operations ... thread ... ... sync ... ... Internal object state Definitions Definitions Dynamic behaviour Dynamic behaviour Synchronization control TIVDM1 Defining Data and Functionality 3 Subclassing and inheritance Where inheritance relationships exist between classes, the inheritor is called subclass and the class from which it inherits is called superclass . • A class can inherit from more than one superclass. •The only restriction on such inheritance multiple is that at most one of the superclass may have a thread definition. • An inheritance relation is indicated by the expression is subclass of after the name of the subclass, followed by a list of the names of its superclasses, separated by commas. TIVDM1 Defining Data and Functionality 4 Name qualification •If several superclasses define a class member with the same name, a name conflict occurs. •This can be resolved by using name qualification in which the name of the member is prefixed by the name of the intended class. •For example, to refer to a type called Sex in a class called Patient : Patient`Sex
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
TIVDM1 Defining Data and Functionality 5 Agenda ! Access Modifiers and Constructors Instance Variables Types Functions Expressions, Patterns, Bindings Operations Statements TIVDM1 Defining Data and Functionality 6 Access Modifiers VDM++ class members may have their access specified as public , private or protected . The default for all members is private . Access modifiers may not be narrowed e.g. a subclass can not override a public operation in the superclass with a private operation in the subclass. static modifiers can be used for definitions which are independent of the object state. TIVDM1 Defining Data and Functionality 7 Constructors Each class can have a number of constructors. Syntax identical to operations with a reference to the class name in return type. The return does not need to be made explicitly. Can be invoked when a new instance of a class gets created. TIVDM1 Defining Data and Functionality 8 A CPRNo Constructor class CPRNo instance variables date : Date; code: Digits4; ... operations CPRNo: Date * Patient`Sex * CPR ==> CPRNo CPRNo(d, sex, cpr) == (date := d; code := cpr.GenerateUniqueCode(d, sex) ); end CPRNo
Image of page 2
TIVDM1 Defining Data and Functionality 9 Agenda " Access Modifiers and Constructors ! Instance Variables Types Functions Expressions, Patterns, Bindings Operations Statements TIVDM1 Defining Data and Functionality 10 Instance Variables (1) Used to model attributes .
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern