Fundamentals of Software Development 1Slide 1 One class can describe many different instancesOne class can describe many different instances –Two NameDroppers,

Slides:



Advertisements
Similar presentations
JAVA Revision Lecture Electronic Voting System Marina De Vos.
Advertisements

OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Fundamentals of Software Development 1Slide 1 Recap: Constructors, the new operator and the this object Three ideas:Three ideas: –How to write a constructor.
Reusable Classes.  Motivation: Write less code!
Fundamentals of Software Development 1Slide 1 Review: Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote.
Department of computer science N. Harika. Inheritance Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
1 Chapter 1 Object-Oriented Programming. 2 OO programming and design Object-oriented programming and design can be contrasted with alternative programming.
Fundamentals of Software Development 1Slide 1 Why have interfaces? A Java interface is the “face” that one class shows othersA Java interface is the “face”
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Fundamentals of Software Development 1Slide 1 Today’s Summary UML class diagrams – –Why classes are important – –UML class diagrams – relationships – –UML.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
Fundamentals of Software Development 1Slide 1 Methods: Defining, Invoking, Executing “There is a difference between knowing the path and walking the path.”
Fundamentals of Software Development 1Slide 1 Interfaces Outline:Outline: –Generic interface versus Java interface –What a (Java) interface is: Its syntaxIts.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Fundamentals of Software Development 1Slide 1 Method invocation versus definition To define (write) a method means to write its codeTo define (write) a.
Programming in Scala Chapter 1. Scala: both object-oriented and functional Scala blends –object-oriented and –functional programming in a –statically.
The Java Keyword this Marie J. Garlitos. Instance Methods First we introduce instance methods: –any method not declared with a static keyword –operates.
1 Java object model Part 3: Serialization & Reflection.
Fundamentals of Software Development 1Slide 1 Outline Designing a computational community for WordGamesDesigning a computational community for WordGames.
Ruby (on Rails) Slides modified by ements-2ed.shtml) 1.
Inheritance using Java
Fundamentals of Software Development 1Slide 1 Why start with WordGames? You wrote your first lines of code in this course in WordGames.You wrote your first.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Fundamentals of Software Development 1Slide 1 Recap: Key ideas in WordGames Defining a classDefining a class Extending a class versus implementing an interfaceExtending.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Computer Science II 810:062 Section 01. How is CS I different from CS II? When you teach Java there are a series of decisions that have to be made…
Classes CS 21a: Introduction to Computing I First Semester,
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Designing a Card Game Solitaire--Thirteens. Game.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
Fundamentals of Software Development 1Slide 1 Correcting Run-Time Errors Small changes and the “What did you just change?” ruleSmall changes and the “What.
Inheritance Fundamentals. Inheritance A derived class extends a base class. It inherits all of its methods (behaviors) and attributes (data) and it may.
 Implementing a class ◦ Implementing an interface ◦ Using documented stubs before coding ◦ Writing JUnit tests before coding ◦ Using fields CSSE 220 Object-Oriented.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
FIT Objectives By the end of this lecture, students should: understand the role of constructors understand how non-default constructors are.
 We have created our two separate 'person' objects, we can set their properties using the methods (the setters) we created.  class person {  var $name;
Java Inheritance 1/13/2015. Learning Objectives Understand how inheritance promotes software reusability Understand notions of superclasses and subclasses.
Utilities (Part 2) Implementing static features 1.
 Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
UML2-1 UML Exercise A "draw" utility program lets users draw several geometric objects on a diagram. A geometric object may be a Circle, Rectangle, Square.
Return to Home! Go To Next Slide! Return to Home! Go To Next Slide!
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
1 More About Derived Classes and Inheritance Chapter 9.
Introduction to Programming using Java
Fundamentals of Software Development 1Slide 1 Today’s Summary InterfacesInterfaces –What are they? –Why are they important? –How do they relate to WordGames?
Fundamentals of Software Development 1Slide 1 Recap: Key ideas in BallWorlds so far Writing a class:Writing a class: –structure –process Writing methods:Writing.
Hello Educational presentation.
Recap: Key ideas in WordGames
Recap: The design of Word Games
Objects as a programming concept
Object Oriented Programming using Java - Class Instance Variables
Classes & Objects: Examples
HELLO THERE. THIS IS A TEST SLIDE SLIDE NUMBER 1.
Implementing Classes Chapter 3.
Assignment 7 User Defined Classes Part 2
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Which best describes the relationship between classes and objects?
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 14 Abstract Classes and Interfaces
Fundamentals of Software Development 1
String Class.
Presentation transcript:

Fundamentals of Software Development 1Slide 1 One class can describe many different instancesOne class can describe many different instances –Two NameDroppers, each with their own myName field In Java, the transform method for NameDropper is:In Java, the transform method for NameDropper is: –this.myName means this instance’s myName field Hello Rumi says Hello Maria says Hello Rumi Maria String transform(String thePhrase) { return this.myName + " says " + thePhrase; return this.myName + " says " + thePhrase;}

Fundamentals of Software Development 1Slide 2 Fields and Constructors A NameDropper must know its name from the very beginningA NameDropper must know its name from the very beginning –We use a constructor to set the field called myName : –Then, when we invoke NameDropper’s constructor, we give it an argument: NameDropper(String whatMyNameIs) { this.myName = whatMyNameIs; } new NameDropper("Rumi"); new NameDropper("Maria");

Fundamentals of Software Development 1Slide 3 Class: Fields, Constructors, Methods public class NameDropper extends StringTransformer implements StringTransformable { private String name; // field: persistent storage, a permanent part // of each NameDropper private String name; // field: persistent storage, a permanent part // of each NameDropper public NameDropper(String whatMyNameIs) { // Constructor public NameDropper(String whatMyNameIs) { // Constructor this.name = whatMyNameIs; this.name = whatMyNameIs; } public String transform(String whatToSay) { // Method public String transform(String whatToSay) { // Method return this.name + " says " + whatToSay; return this.name + " says " + whatToSay; }} Questions? Private means private to the class. The standard is that fields are generally private and all else is public (for now) – more on this later.