1 / 9

Advanced Material

Advanced Material. The following slides contain advanced material and are optional. Outline. CAT calls Generic conformance For more information, see http:// dev.eiffel.com/Comparison_of_catcall_solutions (Some of the information may be outdated…). CAT: Changed availability or type.

heath
Download Presentation

Advanced Material

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Material The following slides contain advanced material and are optional.

  2. Outline • CAT calls • Generic conformance • For more information, see • http://dev.eiffel.com/Comparison_of_catcall_solutions • (Some of the information may be outdated…)

  3. CAT: Changed availability or type • class PARENT • feature • f do end • g (a: ANY) do end • h: ANY • end • classCHILD • inherit • PARENT • redefineg • export{NONE} f end • feature • g (a: STRING) do a.to_upperend • h: STRING • end Restricting export status Covariant redefinition of argument and result type

  4. Problems with CAT • class APPLICATION • feature • make • local • p: PARENT • c: CHILD • do • create {CHILD} p • p.f • p.g (1) • end • end Exported to NONE Wrong argument type will lead to runtime exception

  5. Solution to CAT • Changed availability (restricting export status) • Not allowed anymore in ECMA Eiffel • Covariant result type • This is not a problem • Covariant argument type • Currently checked at run-time • Different solutions proposed, not yet decided on a particular strategy

  6. Generic conformance • classAPPLICATION • feature • make • local • any_list: LIST [ANY] • string_list: LIST [STRING] • integer_list: LIST [INTEGER] • do • string_list := any_list • string_list := integer_list • integer_list := any_list • integer_list := string_list • any_list := string_list • any_list := integer_list • end • end      

  7. Generic conformance vs. changed type • class LIST [G] • feature • put (a: G) do end • first: G • end • interface class LIST [ANY] • feature • put (a: ANY) • first: ANY • end • interface classLIST [STRING] • feature • put (a: STRING) • first: STRING • end LIST [STRING] conforms to LIST [ANY], thus the changed type in the argument and result are like a covariant redefinition.

  8. Problems with generic conformance • class APPLICATION • feature • make • local • any_list: LIST [ANY] • string_list: LIST [STRING] • do • create string_list.make • any_list := string_list • any_list.put (1) • string_list.first.to_upper • end • end Wrong element type

  9. Solutions to generic conformance • Novariant conformance • No conformance between generics of different type • Used by C# • Usage-site variance • Specify conformance for each generic derivation • Used by Java • Definition-site variance • Specify conformance for each generic class • Implemented by CLR

More Related