1 / 28

Object-Oriented Concept

Object-Oriented Concept. Content. Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage / Disadvantage. Object-Oriented Concept. Originated in 1970s. Imitation of things in the real world.

gaenor
Download Presentation

Object-Oriented Concept

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. Object-Oriented Concept

  2. Content Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage / Disadvantage

  3. Object-Oriented Concept Originated in 1970s. Imitation of things in the real world. Interactions between objects form a task.

  4. Class & Object • 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. Class • 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. Class name Name Compartments Data stored in the class Attributes What this class can do Methods Class Notation

  7. University University University University Name Location Faculties No. of Student … KMUTNB BKK {IT, …} 5347 … open close open close … … Example Objects of Class University Class University Instantiate

  8. Class as Programming Code class University { String uName; String location; Collection faculties; intnumberOfStudent; … public void open() {…} public void close() {…} }

  9. What should be a class/object? 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. Object-Oriented Characteristics Encapsulation Inheritance Polymorphism

  11. Encapsulation • 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. Visibility • 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. Inheritance • 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. Class Hierarchy Example Transport Airliner Spacecraft Vehicle Ship Car Truck Train Motorcycle Electric Diesel Maglev Steam-Powered

  15. More Examples Sports Weapons Games Animals Food Drink

  16. Inheritance 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. Implication of Inheritance in Object-Oriented Programming 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. Method Overriding and Overloading • 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. Polymorphism 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. Polymorphism • How do mammals reproduce? • Human, Dogs, Cats, … etc. • What about platypus? • See Transport example again • Referred to method overriding

  21. Relationships Between Classes Association – uses, other common verbs Aggregation – is in Composition – is part of Inheritance / Generalization – is a See UML for correct notation.

  22. How does it work? 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. Example : Borrow books • 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. More Scenarios Order a flower for your friend in England. Buy 2 movie tickets. Make a withdrawal from your bank account. Travel by Skytrain.

  25. Development Tools • Unified Modeling Language (UML) • Specification by Object Management Group (OMG) 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. OO Programming Language http://en.wikipedia.org/wiki/List_of_object-oriented_programming_languages • Java • Cross-platform • Java Virtual Machine • C++ • C# • …

  27. Advantages • 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. Disadvantages Hard to understand for beginner and even some experienced programmers. Object-Oriented programming requires more computation power (no longer matters) Anything else?

More Related