Unit 5: Aggregation and Inheritance - Imperial College London

Unit 5: Aggregation and Inheritance - Imperial College London

Course: Software Engineering Unit 5: Aggregation and Inheritance Aims and Objectives This unit aims to: Define the specification in Object-Z of more elaborated objectoriented systems built upon Objects aggregation Inheritance Illustrate these aspects by considering the example of a banking system that further extends the example credit card accounts system seen in Unit 4. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 1 Course: Software Engineering Example: A Banking System Making many simplifying assumptions:

The system is an aggregate of (set of) credit card account objects. All credit card objects have limit equal to fixed commonlimit. At the beginning, the aggregate is empty. New initialised account object can be added to the aggregate. Any account object in the aggregate can be deleted. Each account object can independently perform withdraw, deposit, withdrawAvail operations. The system shall allow for any given two account objects in the aggregate to transfer the available fund of the first account into the second account. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 2 Course: Software Engineering State Schema for the Class Banking Informally Assume commonlimit to be a constant, whose value is either 1000, or 2000, or 5000. The state of the class Banking includes an attribute cards that is a set of credit card account objects.

commonlimit: N commonlimit {1000, 2000, 5000} cards : F CreditCard c : cards.(c.limit = commonlimit) Init cards = Dr Alessandra Russo Declaration of aggregate as attribute: cards is a finite set of object identities All the accounts objects in the aggregate have the limit equal to commonlimit The initial configuration of this system is when the aggregate is empty. Unit 5: Aggregation and Inheritance, slide number 3 Course: Software Engineering Adding and Deleting Objects Add (cards) newcard?: CreditCard newcard? cards newcard?.Init

newcard?.limit = commonlimit cards' = cards {newcard?} newcards? is genuinely new newcard? is initialised Why do we need this axiom? Delete (cards) cards?: CreditCard card? cards cards' = cards /{card?} Dr Alessandra Russo card? is in the aggregate Unit 5: Aggregation and Inheritance, slide number 4 Course: Software Engineering Selecting Objects from Aggregates Informally The system has to perform the operations of withdraw, deposit and withdrawAvail on the individual account objects that are in the aggregate. We need to promote these objects operations to operations of the Banking system.

This requires a formal notation for selecting the object from the aggregate to which the operation is applied. withdraw = [card? : cards]. card?.withdraw deposit = [card? : cards]. card?.deposit Selection (from the environment) of a particular object in the aggregate to which the operation is applied. Dr Alessandra Russo Only the state of the object identified by card? is changed in the aggregate Unit 5: Aggregation and Inheritance, slide number 5 Course: Software Engineering Selecting more than one Object Informally The system has to allow a transferAvail operation to take place between two given credit card account objects. The fund available has to be transferred from the first object to the second object. transferAvail = [from?, to? : cards | from? to?]. from?.withdrawAvail || to?.deposit

Selection from the set cards of two distinct credit card account objects. These are selected by input from the environment. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 6 Course: Software Engineering The Banking Class Schema Banking | (commonlimit, Init, Add, Delete, withdraw, deposit, withdrawAvail, transferAvail) commonlimit: N commonlimit {1000, 2000, 5000} cards : F CreditCard c : cards. c.limit = commonlimit Add (cards) card? : CreditCard card? cards card?.limit = commonlimit card?.Init cards' = cards {card?}

withdraw = [card?:cards]. card?.withdraw Dr Alessandra Russo Init cards = Delete (cards) card? : CreditCard card? cards cards' = cards / {card?} withdrawAvail = [card?:cards].card?.withdrawAvail transferAvail = [from?:cards, to?:cards | from? to?]. from?.withdrawAvail || to?.deposit. deposit = [card?:cards]. card?.deposit Unit 5: Aggregation and Inheritance, slide number 7 Course: Software Engineering Inheritance In object-oriented programming language: code of existing classes can be reused in coding new classes. In Object-Z formal specification: specifications can be developed incrementally existing Object-Z classes can be reused to define new Object-Z classes

architectural design aspects of the future system are captured inheritance hierarchy of class schemas expresses the class inheritance hierarchy of the future implementation inheritance can be single: a subclass inherits just one other class multiple: a subclass inherits more than one other class Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 8 Course: Software Engineering Example: Specialising the Class CreditCard CreditCard CreditCardCount CreditCardConfirm CreditCard class schema is as defined in Unit4 CreditCardCount class schema refines CreditCard class schema the operation withdraw has also to count the number of withdrawals made CreditCardConfirm class schema extends CreditCard class schema it also includes an operation that first performs the withdraw operation and

then confirms it by producing as output the value of the remaining funds. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 9 Course: Software Engineering Class Schema CreditCardCount CreditCardCount | (limit, balance, Init, withdraw, deposit, withdrawAvail) Inheritance CreditCard withdrawals: N Init withdrawals = 0 withdraw (withdrawals) withdrawals' = withdrawals + 1 Dr Alessandra Russo

Unit 5: Aggregation and Inheritance, slide number 10 Course: Software Engineering Joining Features (state schemas) The full state schema of CreditCardCount: CreditCard CreditCardCount CreditCard . withdrawal: N balance: Z balance + limit 0 . . balance: Z withdrawal: N balance + limit 0

Attributes declared in both schemas must be of the same type. Axioms in the subclass may refer to attributes defined in the superclass. Unintentional name clashes must be resolved by renaming attributes. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 11 Course: Software Engineering Joining Features (Init schemas) The full Initial schema of CreditCardCount: CreditCard CreditCardCount CreditCard . Init Init

withdrawals = 0 balance = 0 . . balance = 0 withdrawal = 0 Axioms are joined together Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 12 Course: Software Engineering Joining Features (operation schemas) The full operation withdraw: CreditCard . withdraw (balance)

amount?:N balance' = balance amount? . withdraw (withdrawals, balance) amount?:N amount? balance + limit balance' = balance amount? withdrawals' = withdrawals +1 Dr Alessandra Russo CreditCardCount CreditCard withdraw (withdrawals) withdrawals' = withdrawals +1 . lists are merged Unintentional operation name clashes are resolved by renaming. Unit 5: Aggregation and Inheritance, slide number 13

Course: Software Engineering Renaming Existing Features CreditCardCount CreditCard[oldwithdraw/withdraw] incrementCount (withdrawals) withdrawals' = withdrawals +1 withdraw = oldwithdraw incrementCount Dr Alessandra Russo Rename the operation in superclass Introduce a new operation Use the old operation name as a new operation name in the subclass Unit 5: Aggregation and Inheritance, slide number 14 Course: Software Engineering Class Schema CreditCardConfirm CreditCardConfirm | (limit, balance, Init, withdraw, deposit, withdrawAvail, withdrawConfirm )

CreditCard fundsAvail funds!: N funds! = balance + limit withdrawConfirm = withdraw 0 9 fundsAvail sequential composition operator Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 15 Course: Software Engineering Summary Aggregates Collection of objects of the same class Use of selection expression in class operations

Inheritance Refining or extending existing super-classes with subclasses Joining features between subclasses and their super-classes Sequential Composition operator. Dr Alessandra Russo Unit 5: Aggregation and Inheritance, slide number 16

Recently Viewed Presentations

  • Classroom Presentation 050456 International Logistic Management To: Students

    Classroom Presentation 050456 International Logistic Management To: Students

    CNGV is an alternative fuel vehicle that uses compressed natural gas (CNG) as a clean alternative to other fossil fuels. Worldwide, there were 14.8 million CNGV by 2011. ... Household & furniture. a. Advantage of Public Warehouse.
  •  Born April 15, 1942 Tyrone, Missouri, USA  Died

    Born April 15, 1942 Tyrone, Missouri, USA Died

    April 17 Enron announces a first quarter profit of $536 million. Lay and other Enron officials meet with Vice President Dick Cheney. May 5 Enron's stock price closes below $59.78, a critical point for one of the partnerships. May 17...
  • A History of Western Society

    A History of Western Society

    Encyclopedia: The Rational Dictionary of the Sciences, the Arts, and the Crafts. 9. Set out to teach people how to think critically. 10. Encyclopedists thought knowledge would increase happiness. ... James Beattie (1735 - 1803) challenged claims of white superiority.
  • Macro Connections Seminar Subnational Productive Complexity ...

    Macro Connections Seminar Subnational Productive Complexity ...

    When one speaks of "demand" in a particular market, this refers to: 2) Demand 2) Supply 2) Equilibrium 3) Comparative statics The number of suppliers of Good D has increased. What will be the effect on the market price and...
  • 2012 JEAA Conference - WordPress.com

    2012 JEAA Conference - WordPress.com

    "An eye for news: Implications of usability research for online news design" 2012 JEAA Conference. Jan Harkin. Research shows 40 per cent of those aged under 30 are regular readers of daily newspapers compared to 62 per cent of older...
  • UW SYSTEM ADMIN Budget and Accounting Training

    UW SYSTEM ADMIN Budget and Accounting Training

    Budget Categories. GPR - General purpose revenues consisting of general taxes, miscellaneous receipts and revenues collected by state agencies which are deposited into the general fund and are available for appropriation by the legislature.
  • Alkoholilakiluonnos: lausunnot - Alcohol Action Ireland

    Alkoholilakiluonnos: lausunnot - Alcohol Action Ireland

    Advertising for beverages above 2,8% abv was banned, also indirect advertising through non-alcohol products. Low-alcohol beer fell outside the ban. The loophole was used to promote stronger beers of the same brand. Expenditure on low-alcohol beer advertising equalled 20% of...
  • Accountability Expert Panel

    Accountability Expert Panel

    AHSC AFP Accountability: Information and Feedback Session May 4, 2007 Jenkins Lecture Theatre Sunnybrook Health Sciences Centre Toronto Introductions Dr. Chris Morgan, Chair, AHSC AFP Accountability Expert Panel Panel Members: Nan Brooks, Chair, AHSC AFP Accountability Working Group Rami Rahal,...