Welcome to Principles of Object Oriented Programming 202
Welcome to Principles of Object Oriented Programming 202 -1 -5181 Teaching assistants Hagit Bachmat Email: hagitb@post. bgu. ac. il Tel: 08 -6472181 Office Hours: Mon 10: 00 -12: 00 @ 37/-113 (By appointment) Tal Barami Email: baramit@post. bgu. ac. il Tel: 08 -6477809 Office Hours: Tue 14: 00 -16: 00 @ 37/-101 (By appointment) Course homepage: https: //www. cs. bgu. ac. il/~oosd 202/Main Assignments: 3 (In pairs) Grade*: 30% Assignments (5%, 10%, 15%) 70% Final exam Course requirements*: 56+ Exam 56+ Course (Exam+assignments) *See full details at the course home page
ZOOM Profile Please update your zoom profile so we’ll know to whom we are talking to 3
? מה בתירגולים : בתירגולים שנלמד הנושאים של חלקית רשימה • UML class diagrams • Packages, Classpath, Jar Files • Collections & Wrappers • Design Patterns - Observer, Singleton, and Visitor • C++ (Focusing on the differences from Java) • Multiple Inheritance • Overloading and Overriding • Generics 4
? מה נלמד היום : ראשון חלק • Packages • Class Path • JAR Files : שני חלק • UML Class Diagrams 5
Packages Package rules: • Each class belongs to a package (which will hold related classes) • Package may have sub-packages • A package path is dot-separated • foo. goo. Boo Class Boo, sub-package goo, package foo 6
Packages Package declaration (In the beginning of the class) package foo. goo; class Boo {. . . } Importing classes from other packages import java. util. Array //Import only the Array class import java. util. *; //All classes in java. util 7
Finding a class Where the JRE looks for a. class file? • Default classpath - The working directory (“. ”) • CLASSPATH 1. Overrides the default classpath 2. An environment variable that specifies several locations of classes/packages 3. Search order is as appear in the CLASSPATH • The search starts from the classpath down to directories that match the package path. Intuitively, Sub-package = Sub-directory. • Example: foo. goo. Boo 8
JAR Files A jar file is a zip archive that contains: • . class files • Other needed resources (images, config files, manifest file) • Source files (optional) • Equivalent to libraries in java 9
Using JAR Files • You can run a jar file by running: java -jar hello-world. jar • The Java Runtime will load all the content of the jar and will run the main class. • Creating a jar file using the command-line tool: jar cf <jar-file> <manifest-file> files
Or do it with Eclipse
Or Intellij (Better!) After adding the module (and possibly the main class), select OK. 12
Or Intellij (Better!) • If you want to add your source code to the jar file, click on the ‘+’ icon and choose “module Sources”. Once done, click OK. • Select the “Build” tab from the intellij menu and choose “Build Artifacts”, then select “Build”. • You can find your jar file in the “out” folder. If you made changes to your code, simply choose “Rebuild”. 13
Unified Modeling Language (UML) 14
What is a model? • An abstraction of software features • A structure that singles out selected features • Independent from other software elements (Platform, language, etc…) • Usually visual (diagrammatic) 15
UML • The UML is a standard for software specification and design. • It’s a modeling Language. • Why do engineers build models? 1. To understand 2. To communicate 3. To predict 4. To specify (Blueprints) • Building models is realized by selecting statements through abstraction, i. e. , reduction of information preserving properties relative to a given set of concerns. From: Bran Selic, UML 2 Tutorial @ Mo. DELS 2012 16
UML Class Diagram 17
+ OCL (Object Constraint Language) 18
Class – An entity that defines: • Properties. • Behavior. • Relationships to other classes. • Semantics. Information Object is an instance of a class. Some classes may not have instances (static classes). For example, Math. For Example: 19
Class Visibility Access Level: • Public – ‘+’, Accessed by everyone • Protected – ‘#’, Accessed by self, subclasses and members of the same package • Private – ‘-’, Accessed by self only For Example: Circle - centre. X: Int - centre. Y: Int + draw() # move(Int X, Int Y) 20
Abstract Class Name* Car * - engine. Size : int Fields (Attributes) - max. Speed : int # get. Max. Speed() : int Non Abstract Methods + drive() * Abstract methods * 21
UML Class Diagrams • Interrelationships: ØAssociation ØGeneralization (Inheritance, Subtyping, Extends, is a) ØRealization (Interface, Implements) 22
Association is a relationship that describes a logical link between two classes. For example, a person works for a company: Role Person employee employer Company works for Association Name This type of association is a plain association. 23
Association - Multiplicity • A Person can work for up to 3 Companies. • A Person has to work for at least one Company. • Unlimited Persons can work in a Company. • A Company should have at least 1 Persons. Person employee 1. . * works for employer 1. . 3 Company 24
Association Common mistakes Association VS attribute ◦ Associations are the essence of object-oriented modeling. Connections between objects are always modeled as links. ◦ Attributes provide additional (secondary) information about identified objects. ◦ Attribute heuristic rule: If it’s important it’s not an attribute! 25
Association Common mistakes Roles VS Objects A Person has exactly two Parents and any number of children 26
Generalization • Generalization relationship Inheritance relationship. • Generalization – A collection of shared properties and services that is extracted to a Super. Type class • A Sub. Type inherits the properties, services and relationships from the Super. Type class (and of course can extend them). 27
Realization • A realization relationship indicates that one class implements a behavior specified by an interface(s) • An interface can be realized by many classes • A class may realize many interfaces <<interface>> Linked. List Array. List <<interface>> Array 29
Tools Web based UML tool 31
END 32
- Slides: 32