Download presentation
Presentation is loading. Please wait.
Published byRoberta Thornton Modified over 8 years ago
1
1
2
2 Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage / Disadvantage
3
3 Originated in 1970s. Imitation of things in the real world. Interactions between objects form a task.
4
4 Class is a template of objects of a same kind or type. Person Movie University Object is an instantiation of class. Leonardo da Vinci The Hobbit KMUTNB Many objects of the same class have the same set of attributes and behavior but their values may vary.
5
5 Class contains: Class name. Attributes or data of that class. Type of each attribute should be specified. Methods (operations / functions) or what that class can do or the behavior of that class.
6
6 Name Attributes Methods Compartments Class name Data stored in the class What this class can do
7
7 Class University University Name Location Faculties No. of Student … open close Instantiate Objects of Class University University KMUTNB BKK {IT, …} 5347 … open close University … …
8
8 class University { String uName; String location; Collection faculties; int numberOfStudent; … public void open() {…} public void close() {…} }
9
9 What are you interested in? Both concrete and abstract. Is it just a value? - attribute Or is it composed of a group of data? Similar to identifying Entities in ERD.
10
10 Encapsulation Inheritance Polymorphism
11
11 Data are hidden within object. Methods are included in the object. Communication with the object is through methods (interface) In OOP, class usually has setters and getters methods E.g. from University public void setUniversityName(String newName) { uName = newName; } public String getUniversityName() { return uName; }
12
12 Three levels of visibility Public – Visible to all Private – Visible to that class only Protected – Visible to that class and its subclasses Unspecified (Java only) – Visible to all within the same package or folder (not recommended, especially in large- scale program)
13
13 A class formed by inheriting the attributes and behavior of another class. Class A inherits from Class B Class A is a subclass of the parent class B. Class B is a parent class of the subclass A. Can a class inherit from 2 parent classes? Subclass / Derived Class Parent Class / Base Class / Superclass
14
14 Transport Airliner ShipVehicle CarTruckMotorcycleTrain Steam-Powered ElectricDieselMaglev Spacecraft
15
15 Sports Weapons Games Animals Food Drink
16
16 Subclass initially has the same attributes and methods as its parent class. Subclass can alter or override the inherited attributes and methods. Subclass can add new attributes and methods. How is inheritance useful? Help reuse source code – how?
17
17 Subclass can be passed as argument for method that specifies its parent class as parameter But not the other way around! Why? How useful?
18
18 Method Overriding A method in a subclass with the same name, parameter set, and return type as the method in its parent class. Method Overloading A method in a class with the same name and return type but different parameter set as a method in the same class or its parent class. public void getName() {…} public void getName(String type) {…} public void getName(int type) {…}
19
19 Poly = Many, Morph = Form Invoking a method name may give different action and/or result depending on the kinds of objects. What would you do when you are told to “Find one million Baht” ? “Play your favorite sport”?
20
20 How do mammals reproduce? Human, Dogs, Cats, … etc. What about platypus? See Transport example again Referred to method overriding
21
21 Association – uses, other common verbs Aggregation – is in Composition – is part of Inheritance / Generalization – is a See UML for correct notation.
22
22 You need to know what each object can do (methods) and how to use them. You don’t need to know the detail of the methods. Tell the object to do something by calling its methods and give proper parameters. A task is form by interactions among objects. Imitation of the real world activities. Parameter vs Argument
23
23 Logically Student tells the librarian who he/she is. Student tells the librarian which books he/she wants to borrow. The librarian records the loan. The librarian tells the student by which date he must return the books.
24
24 Order a flower for your friend in England. Buy 2 movie tickets. Make a withdrawal from your bank account. Travel by Skytrain.
25
25 Unified Modeling Language (UML) Specification by Object Management Group (OMG) www.omg.org www.omg.org Consist of 9 diagrams to explain a system. Rational Rose Object-Oriented software development tool utilizing UML. Provide source code generation. Microsoft Visio
26
26 Java Cross-platform Java Virtual Machine C++ C# … http://en.wikipedia.org/wiki/List_of_object-oriented_programming_languages
27
27 Support source code reuse. Faster development time. Both data and operation aspects are combined. Object-Oriented software are easier to maintain. Low dependency between objects. An object can be replaced easily with minimum modification to other objects.
28
28 Hard to understand for beginner and even some experienced programmers. Object-Oriented programming requires more computation power (no longer matters) Anything else?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.