1 / 18

Classes

Classes. Lecture OO03 Representing Classes. References. Ambler, S., The Object Primer , Cambridge Univ. Press, 2001, Chapter 1 & 2, Sections 5.1 - 5.5 Fowler & Scott, UML Distilled Applying the Standard Object Modelling Language, AWL, 1997, Chapt 6. Teaching Points.

amy
Download Presentation

Classes

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. Classes Lecture OO03 Representing Classes

  2. References • Ambler, S., The Object Primer, Cambridge Univ. Press, 2001, Chapter 1 & 2, Sections 5.1 - 5.5 • Fowler & Scott, UML Distilled Applying the Standard Object Modelling Language, AWL, 1997, Chapt 6

  3. Teaching Points • Introduction to class representations • Introduction to Java classes • Introduction to packages

  4. Review • What is an object? • Why is the object model useful for describing problem domains? • What is a pattern? • Describe the Composite pattern.

  5. OOA/OOD/OOPL Supports • Abstraction • Encapsulation • Modularity • Hierarchy • Typing • Concurrency • Persistance

  6. Abstraction • A UML Class • abstract data type

  7. Recall struct in C Classes in Java struct EmpRec{ char name[45]; int age; char address[256]; }; EmpRec student; student.age = 27;

  8. A Java Class class Vehicle{ private int wheels; private float weight; public void initialize(int wh, float wt) { wheels = wh; weight = wt; } public int getWheels(void) { return wheels; } public float getWeight(void) { return weight; } public float wheelLoading(void) { return weight/wheels; } }

  9. Manipulating an object Vehicle v; v = new vehicle(); v.initialize(4, 1050.0); int w = v.getWheels(); float l = v.wheelLoading();

  10. UML Packages • A mechanism for grouping things • In this course packages will mainly be groupings of classes • Packages can be nested

  11. Java Packages • Each class is a member of a package • An object can ‘use’ the class specifications for other classes in the package of ‘its’ class • To use the specification of classes which are not in its package an object must import the class

  12. Using Java Packages • Explicit names • The package keyword • The import keyword • importing a class • importing a package • The unnamed package • java.lang is always imported

  13. Java Packages and Directories • Strong relationship between packages and directories in the Java environment • The concept of CLASSPATH • resolving a package name

  14. Encapsulation • There must be a mechanism to limit access to the secret of the class. • Members of the class need to access the secret • a class is a scope • Different from block statements • context based on information hiding (often data) and not on procedural decomposition

  15. Access Control • public • protected • unnamed • called :friendly (default) • private • Note: each level of access subsumes the level below it

  16. Modularity • Class is a unit of decomposition • so is a module • Encapsulation is about logical decomposition • Modularity is about physical decomposition • Modules allow independent design, implementation, compiling, revision

  17. Java Modules • Closely related to classes • One public class allowed per file • Multiple non-public classes allowed per file • non-public classes are only visible to the package to which they belong • Note: access control here is similar to that for class members non-public access is like friendly

  18. Teaching Points • Introduction to class representations • Introduction to Java classes • Introduction to packages

More Related