High-Level Programming Languages II

High-Level Programming Languages II

Zoltán Hernyák High-Level Programming Languages II. Object-Oriented Programming in practice ZOLTÁN HERNYÁK High-Level Programming Languages II. draft version 2014.03.14 Zoltán Hernyák High-Level Programming Languages II. Object-Oriented Programming in practice Eger 2012 Author Hernyák Zoltán PhD associate professor Eszterházy Károly College Lector Table of contents Tartalom Table of contents .................................................................................................................. 3 1. Introduction .................................................................................................................. 8 2. The history of OOP ......................................................................................................12 3. The principles of OOP ..................................................................................................15 4. The classification of imperative languages .................................................................18 5. A simple example for an OOP problem .......................................................................20 6. Data hiding ..................................................................................................................24 6.1. To protect the value of a field ...............................................................................26 6.2. A solution with methods .......................................................................................27 6.3. Error indicating ....................................................................................................30 6.4. Protected instead private .....................................................................................32 6.5. Why is the private the default protection level? ..................................................33 6.6. Property ................................................................................................................34 6.7. When we might think no protection is needed .....................................................37 6.8. Writeable once fields .............................................................................................38 6.9. Read only fields .....................................................................................................40 6.10. A more effective solution ...................................................................................42 7. Methods ........................................................................................................................43 7.1. Instance-level methods .........................................................................................44 7.2. Handling the actual instance ...............................................................................46 8. The function Main ........................................................................................................50 9. The constructors ..........................................................................................................53 9.1. Constructors during the instantiation .................................................................54 9.2. Creating a constructor ..........................................................................................55 9.3. Creating several constructors ...............................................................................56 9.4. Lack of constructor ...............................................................................................57 9.5. Checking the parameters .....................................................................................58 9.6. Write-once fields ...................................................................................................59 9.7. A property with two different protection level .....................................................60 9.8. The real write-once fields .....................................................................................61 9.9. Constants ..............................................................................................................62 10. The data members ....................................................................................................64 10.1. Instance level fields ...........................................................................................64 10.2. Class level fields ................................................................................................66 10.3. Constants ...........................................................................................................67 11. The inheritance ........................................................................................................69 11.1. The inheritance of the fields .............................................................................69 11.2. Problems around fields inheritance ..................................................................71 11.3. The keyword ‘base’ ............................................................................................75 11.4. Inheritance of the methods ...............................................................................76 11.5. The problems around method inheritance ........................................................78 11.6. The methods and the ‘base’ ...............................................................................81 11.7. The real problems around the inheritance of the methods ..............................82 12. Type compatibility ....................................................................................................84 12.1. The consequences of the type compatibility .....................................................85 12.2. The Object class .................................................................................................90 12.3. The static and the dynamic type .......................................................................91 12.4. The operator ‘is’ .................................................................................................92 12.5. Early binding and its problems .........................................................................92 13. The virtual methods .................................................................................................97 13.1. The override and the property ..........................................................................98 13.2. Other rules of override ......................................................................................99 13.3. Manual late binding – the ‘as’ operator .......................................................... 101 13.4. When the type cast is the only help ................................................................ 105 13.5. Typecast is not an ultimate weapon ............................................................... 105 13.6. The story of kangaroos .................................................................................... 108 14. Problems with the constructors ............................................................................. 110 14.1. The constructor call chain ............................................................................... 111 14.2. Constructor identification chain ..................................................................... 112 14.3. To call an constructor with “this” ................................................................... 115 14.4. To call an own constructor and the constructor identification chain ............. 118 14.5. To call an ancestor class constructor explicitly with ‘base’ ............................ 118 14.6. Class-level constructors .................................................................................. 120 14.7. Private constructors ........................................................................................ 123 14.8. The keyword ‘sealed’ ....................................................................................... 124 14.9. The Object Factory .......................................................................................... 126 15. The indexer ............................................................................................................. 130 16. Namespaces ............................................................................................................ 136 17. The Object class as the ancestor ............................................................................ 144 17.1. GetType() ......................................................................................................... 144 17.2. ToString() ........................................................................................................ 145 17.3. Equals() ........................................................................................................... 146 17.4. GetHashCode() ................................................................................................ 147 17.5. Boxing – Unboxing .......................................................................................... 148 17.6. The list of Object ............................................................................................. 151 17.7. An object parameter ........................................................................................ 154 18. The abstract classes ............................................................................................... 157 19. VMT and DMT.......................................................................................................

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    296 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us