Week 9 Generalization, inheritance, class hierarchy and graphics.

Slides:



Advertisements
Similar presentations
Graphics Programming. Introduction GOAL: Build the Indexer Client Event-driven vs. Sequential programs Terminology – Top-level windows are called “frame.
Advertisements

1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Inheritance Reserved word protected Reserved word super
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Inheritance (notes for 10/26 lecture). Inheritance Inheritance is the last of the relationships we will study this semester. Inheritance is (syntactically)
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
Inheritance COMP53 Sept Inheritance Inheritance allows us to define new classes by extending existing classes. A child class inherits all members.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
GUI and event-driven programming An introduction.
WHAT IS INHERITANCE? Java Unit 11: Inheritance I.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
CPS Today’s topics Java Language Inheritance Upcoming Electric Circuits (not in text) Reading Great Ideas, Chapters 5.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance Abstract Classes Check out Inheritance from SVN.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
CSE 219 Computer Science III Graphical User Interface.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Inheritance and Access Control CS 162 (Summer 2009)
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
Review_6 AWT, Swing, ActionListener, and Graphics.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Coming up: Inheritance
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
TCU CoSc Programming with Java The JFrame Class.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Inheritance and Polymorphism
Week 4 Object-Oriented Programming (1): Inheritance
An Introduction to Inheritance
Chapter 3 Inheritance © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
MSIS 670 Object-Oriented Software Engineering
Advanced Programming Behnam Hatami Fall 2017.
Object-Oriented Programming: Inheritance and Polymorphism
Presentation transcript:

Week 9 Generalization, inheritance, class hierarchy and graphics

Review We have seen interfaces that specify capabilities (I.e., methods) but do not define them. Any class that implements an interface must define those methods. The big take-home point is that an interface doesn’t care how a particular class implements a method; only that it indeed has that method defined.

Interfaces An interface can extend one or more interfaces. This is the last of the five relationships. Can you name, draw a UML and show the code for each? Formal name is Generalization. Informal name is “extends” or “is a”. Two types of generalization: one from interface to interface and one from class to class.

Interfaces What does it mean to have an interface extend another interface? The method specifications in the super- interface(s) are carried down the chain. Any class that implements an interface, must define all the methods in its immediate parent interface(s) and all methods specified in any interfaces that its parent(s) extends from

Interfaces See UML Why? Gets complicated. However, the big idea is decoupling, generalization and therefore specialization. We want our code to be strong. Not muscle bound and rigid, but flexible and adaptable. This is as in Life. Remember who told you that.

Inheritance Classes can extend other classes as well. We say that classes inherit from other classes. What do they inherit? Anything that is public or protected. Unlike interfaces, though, a class can extend from only one class. A class can have only only one direct superclass. Multiple classes can extend from it, however; i.e., a class can have multiple subclasses.

Inheritance public class A extends B{ } We say:A is a B A inherits from B A extends B A is the subclass or child B is the superclass or parent B generalizes A

Class Hierarchy There is a hierarchy to all classes in Java. All classes have parents or superclasses. Except one. The top class is java.lang.Object. Learn it, love it, know it. Every class in Java is an Object, either directly or indirectly.

Why reinvent the wheel? We extend a class already written so we can specialize that class and save valuable time for ourselves. We get all the parent’s capabilities and parent’s parent’s capabilities and so on. Humans are lazy. This is doubly true for programmers. Remember who told you that.

Graphics javax.swing We give you the Classlibs with our modified javax.swing classes that help get you started in the fun, tedious, frustrating and ridiculously time consuming world of Java graphics.

Graphics We have containers, components and graphics Components are javax.swing mostly. Some components are JButton, JSlider and JLabel. We give you some specific containers like containers.Row and containers.Column. These act as layout managers for anything that gets added to them. Rows add items left to right and columns add items top to bottom. There is also the javax.swing.JFrame container. This is usually the top level or outermost container. Always remember to setVisible(true), pack(), and setDefaultCloseOperation(EXIT_ON_CLOSE).

Graphics Everything, except the outermost Frame is added to something else. Everything is nested in another container. We often extend these classes so we can specialize them. Some graphics are Ellipse, Rectangle, Image and Color. All graphics are added to a special container, which is called graphics.DrawingCanvas. Your fellow students and teaching staff will shun and ridicule you if you ever try to add a graphics.Rectangle3D to a containers.Row Always remember to setDimension(), setColor(), setLocation() of your graphics. Default dimension is (0,0), default color is gray, and default location is (0,0)  that is upper left corner of screen. The ONLY way to learn graphics is try it out and make lots of mistakes until it looks and behaves like you want it to.