Composing Methods. Extract Method - Code that can be grouped - Meaningful name for method
|
|
- Kelley Morgan
- 5 years ago
- Views:
Transcription
1 Composing Methods Extract Method - Code that can be grouped - Meaningful name for method Inline Method - inverse of Extract Method - Method body is more obvious Extract Variable - Expression: hard to understand - Separate self-explanatory var Inline Temp Replace Temp with Query - Temp var holding expression - Extract Expression into method Split Temporary Variable - different var for different value void printowing(double amount){ //print details System.out.println( name: +name); System.out.println( amount: + amount); void printowing(double mount){ printdetails(name, amount); void printdetails(string name, double amount){ System.out.println( name: +name); System.out.println( amount: + amount); int getrating() { return (morethanfivelatedeliveries()?2:1; Boolean morethanfivelatedeliveries() { return numberoflatedeliveries > 5; int getrating() { return (numberoflatedeliveries >5)?2:1; if((platform.touppercase().indexof( MAC ) > -1) && (browser.touppercase().indexof( IE ) > -1) && wasinitialized() && resize > 0) { //do something final boolean ismacos = platform.touppercase().indexof( MAC ) > -1; final boolean isiebrowser = browser.touppercase().indexof( IE ) > -1; final Boolean wasresized = resize > 0; if (ismacos && isiebrowser && wasinitialized() && wasresized) { //do something double baseprice = anorder.baseprice(); return (baseprice > 1000); return (anorder.baseprice() > 1000); double baseprice = quantity * itemprice; if (baseprice > 1000) return baseprice * 0.95; else return baseprice; if (baseprice() > 1000) return baseprice() * 0.95; else return baseprice() * 0.98; double baseprice() { return quantity * itemprice; double temp = 2 * (height + width); System.out.println(temp); temp = height * width; System.out.println(temp); 1 11
2 Composing Methods Remove Assignments to Param - use temp var instead Replace Method with Method Obj - Extract Method cannot be applied - Separate class Substitute Algorithm - Replace existing algorithm - Replace body of the method final double perimeter = 2 * (height + width); System.out.println(perimeter); final double area = height * width; System.out.println(area); int discount(int inputval, int Quantity, int yeartodate){ if (intputval>50) inputval -=2; int discount(int inputval, int Quantity, int yeartodate) { int result = inputval; if (inputval > 50) result - = 2; class Order { double price() { double primarybaseprice; double secondarybaseprice; double TeriaryBasePrice; //long computation class Order { public double price() { return new PriceCalculator(this).compute(); class PriceCalculator { private double primarybaseprice; private double seconadarybaseprice; private double tertiarybaseprice; PriceCalculator(Order order) { //copy relevant info public double compute() { // String foundperson(string[] people) { for(int I = 0;i<people.length;i++) { if(people[i].equals( Don )) return Don ; if((people[i].equals( John )) return John ; if(people[i].equals( Kent )) return Kent ; return ; 2 11
3 Composing Methods Moving Feature btwn Obj Move Method - Use more features in another class Move Field - Field used by another class more String foundperson(string[] people) { ListCandidates = Arrays.asList(new String[] { Don, John, Kent ); for(int i = 0;i<people.length;;i++) { if (candidates.contains(people[i])) { return people[i]; return ; Extract Class - One class does the work of two Inline Class - Class does almost nothing Hide Delegate - use A for getting B info - new method of A delegating B Remove Middle Man - too many methods that simply delegate - force the client to call the end methods directly Introduce Foreign method - server class cannot contain the needed class - add a method in the client Date newstart = new Date(previousEnd.getYear(), previousend.getmonth(), previousend.getdate() + 1); Date newstart = nextday(previousend); private static Date nextday(date arg) { return new Date(arg.getYear(), arg.getmonth(), arg.getdate() + 1); 3 11
4 Moving Feature btwn Obj Organizing Data Introduce Local Extension - server class cannot contain some methods that you need Self Encapsulate Field - Create a getter and setter Replace Data Value with Object - Contain a data field with its own behavior and associated data - Change the data item into an object Change Value to Reference - Many identical instances of a single class - Converted to a single reference object Change Reference to Value - Reference object is too small - Converted it into a value object Replace Array with Object - Arrays containing various types of data - Replace array with an object Duplicate Observed Data - Domain data in GUI control - Copy data to model and set up observer private int low, high Boolean includes(int arg) { return arg >= low && arg <= high; private int low, high Boolean includes(int arg) { return arg >= getlow() && arg <= gethigh(); int getlow() { return low; int gethigh() { rturn high; String[] row = new String[]; row[0] = Liverpool ; row[1] = 15 ; Performance row = new Performance(); row.setname( Liverpool ); row.setwins( 15 ); Change Unidirectional Association to Bidirectional - Add missing association Change Bidirectional Association to Unidirectional - Remove unused association 4 11
5 Organizing Data Replace Magic Number with Symbolic Constant - number having a certain meaning - Replace with constant double potentialenergy(double mass, double height) { return mass * 9.81 * height; double potentialenergy(double mass, double height) { return mass * GRAVITATION_CONSTANT * height; static final double GRAVITATION_ONSTANT = 9.81; Encapsulate Field - make public field as private - provide accessors Encapsulate Collection - Collection Field with a simple getter/setter - Getter returns read-only, Setter replaced with adding/removing elements Replace Type Code with Class - fields containing type code - Create a new class and use its objects instead (Obsolete: Java enumeration is another option) Replace Type Code with Subclasses - immutable type code affecting the behavior - Create subclasses for each value (OCP) public String name; private String name; public String getname() { return name; public String setname(string arg) { name = arg; Replace Type Code with State/Strategy - Type code affects behavior, but cannot use subclassing - Replace Type code with State/Strategy Replace Subclass with Fields - Subclass differs in constant-returning methods - Remove subclass 5 11
6 Simplifying Conditional Expression Decompose conditional - Complex conditional - Decompose to separate methods if(data.before(summer_start) date.after(summer_end)) charge = quantity * winterrate + winterservicecharge; else charge = quantity * summerrate; if(notsummer(date)) charge = wintercharge(quantity); else charge = summercharge(quantity); Consolidate Conditional Expression double disabilityamount() P if (seniority < 2) if(mounthsdisabled > 12) if (ispattime) double disabilityamount() { if(isnorteligablefordisability()) Consolidate Duplicate Conditional if (isspecialdeal()) { Fragments total = price* 0.95; send(); else { total = price * 0.98; send(); if (isspecialdeal()) { total = price* 0.95; else { total = price * 0.98; send(); Remove Control Flag void checksecurity(string[] people) { boolean found = false; for (int i = 0; i < people.length; i++) { if (! found) { if (people[i].equals ("Don")){ sendalert(); found = true; if (people[i].equals ("John")){ sendalert(); found = true; 6 11
7 Simplifying Conditional Expression Remove Control Flag void checksecurity(string[] people) { boolean found = false; for (int i = 0; i < people.length; i++) { if (people[i].equals ("Don")){ sendalert(); found = true; break; if (people[i].equals ("John")){ sendalert(); found = true; break; Replace Nested Conditional with Guard double getpayamount() { Clauses double result; if (_isdead) result = deadamount(); else { if (_isseparated) result = separatedamount(); else { if (_isretired) result = retiredamount(); else result = normalpayamount(); ; return result; ; double getpayamount() { if (_isdead) return deadamount(); if (_isseparated) return separatedamount(); if (_isretired) return retiredamount(); return normalpayamount(); ; Replace Conditional with Polymorphism Introduce Null Object Introduce Assertion double getexpenselimi() { //should have either expense limit or a primary project return (expenselimit!= NULL_EXPSENSE)? expenselimit ;:primaryproject.getmemberexpenselimit() 7 11
8 Simplifying Conditional Expression Simplifying Method Calls Rename Method double getexpenselimi() { Assert.isTrue(expenseLimit!=NULL_EXPENSE primaryproject!= null); return (expenselimit!= NULL_EXPSENSE)? expenselimit ;:primaryproject.getmemberexpenselimit() Add Parameter Remove Parameter Separate Query from Modifier Parameterize Method Replace Param with Explicit Method void setvalue (String name, int value) { if (name.equals("height")) _height = value; if (name.equals("width")) _width = value; Assert.shouldNeverReachHere(); void setheight(int arg) { _height = arg; void setwidth (int arg) { _width = arg; Preserve Whole Object int low = daystemprange().getlow(); int high = daystemprange().gethigh(); withinplan = plan.withinrange(low, high); withinplan = plan.withinrange(daystemprange()); Replace Parameter with Method Call int baseprice = _quantity * _itemprice; discountlevel = getdiscountlevel(); double finalprice = discountedprice (baseprice, discountlevel); int baseprice = _quantity * _itemprice; double finalprice = discountedprice (baseprice); Introduce Parameter Object 8 11
9 Simplifying Method Calls Remove Setting Method Hide Method Dealing with Generalizatio n Replace Constructor With Factory Employee (int type) { Method _type = type; static Employee create(int type) { return new Employee(type); Encapsulate Downcast Object lastreading() { (Needed?) return readings.lastelement(); Reading lastreading() { return (Reading) readings.lastelement(); Replace Error Code With Exception int withdraw(int amount) { if (amount > _balance) return -1; else { _balance -= amount; void withdraw(int amount) throws BalanceException { if (amount > _balance) throw new BalanceException(); _balance -= amount; Replace Exception With Test double getvalueforperiod (int periodnumber) { try { return _values[periodnumber]; catch (ArrayIndexOutOfBoundsException e) { double getvalueforperiod (int periodnumber) { if (periodnumber >= _values.length) return _values[periodnumber]; Pull Up Field 9 11
10 Dealing with Generalizatio n Pull Up Method Pull Up Constructor Body Push Down Method class Manager extends Employee... public Manager (String name, String id, int grade) { _name = name; _id = id; _grade = grade; public Manager (String name, String id, int grade) { super (name, id); _grade = grade; Push Down Field Extract Subclass Extract Superclass Extract Interface Collapse Hierarchy 10 11
11 Dealing with Generalizatio n From Template Method Replace Inheritance with Delegation Replace Delegation with Inheritance Big Refractorings Tease Apart Inheritance Convert Procedural Design to Objects Separate Domain from Presentation Extract Hierarchy 11 11
Badge#8: Geek Refactoring
Badge#8: Geek Refactoring Nuno Pombo, Qualidade de Software, 2018/19 1 When To Refactor? Rule of Three When adding a feature When fixing a bug During a code review 2 How To Refactor? The code should become
More informationRefactoring. Refactoring. Refactoring. Refactoring. Refactoring. Refactoring. Lesson Five: Conditionals
Lesson Five: should not be too complex. If they are complex, refactor them to make simple methods making readability and understandability better. Learning objective have simple conditionals which are
More informationRefactoring. Thierry Sans. with slides from Anya Tafliovich
Refactoring Thierry Sans with slides from Anya Tafliovich Composing Methods Extract Method void printowing() { printbanner(); //print details System.out.println("name: " + name); System.out.println("amount:
More informationEECS 4314 Advanced Software Engineering. Topic 10: Software Refactoring Zhen Ming (Jack) Jiang
EECS 4314 Advanced Software Engineering Topic 10: Software Refactoring Zhen Ming (Jack) Jiang Acknowledgement Some slides are adapted from Professor Marty Stepp, Professor Oscar Nierstrasz Relevant Readings
More informationRefactoring Maintenance Evolution 10/31/2014. MTAT Software Engineering. Assessment Slide from Lecture 1
MTAT.03.094 Software Engineering Lecture 08: Refactoring Fall 2014 Dietmar Pfahl email: dietmar.pfahl@ut.ee Assessment Slide from Lecture 1 Next Labs Week: 70% of total grade Evaluation Exam 30% of total
More informationChapter 7: Simplifying Conditional Expressions
Chapter 7: Simplifying Conditional Expressions Conditional logic has a way of getting tricky, so here are a number of refactorings you can use to simplify it. The core refactoring here is Decompose Conditional
More informationRefactoring. So#ware Quality Quality Audit and Cer4fica4on. Master in Computer Engineering. Roberto García
Refactoring So#ware Quality Quality Audit and Cer4fica4on Master in Computer Engineering Roberto García (rgarcia@diei.udl.cat) Introduc4on When considering soaware evolu4on, the key dis4nc4on is: Program's
More informationCLEAN CODE, CODE SMELLS, REFACTORING
CLEAN CODE, CODE SMELLS, REFACTORING AND RELATED PRINCIPLES Barbora Bühnová buhnova@fi.muni.cz LAB OF SOFTWARE ARCHITECTURES AND INFORMATION SYSTEMS FACULTY OF INFORMATICS MASARYK UNIVERSITY, BRNO Outline
More informationJUnit 3.8.1, 64. keep it simple stupid (KISS), 48
Index A accessor methods, 11, 152 add parameter technique, 189 190 add() method, 286 287, 291 algorithm, substituting, 104 105 AND logical operator, 172 architectural design patterns, 277 278 architecture,
More informationCOURSE 11 DESIGN PATTERNS
COURSE 11 DESIGN PATTERNS PREVIOUS COURSE J2EE Design Patterns CURRENT COURSE Refactoring Way refactoring Some refactoring examples SOFTWARE EVOLUTION Problem: You need to modify existing code extend/adapt/correct/
More informationRefactoring. Joseph W. Yoder. The Refactory, Inc. The Refactory Principals.
Refactoring Joseph W. Yoder The Refactory, Inc. joe@refactory.com http://www.refactory.com The Refactory Principals John Brant Don Roberts Brian Foote Joe Yoder Ralph Johnson Refactory Affiliates Joseph
More informationvoid printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) {
Refactoring References: Martin Fowler, Refactoring: Improving the Design of Existing Code; ; Bruce Wampler, The Essence of Object-Oriented Oriented Programming with Java and UML A recent OO technique that
More informationCourse December Adrian Iftene
Course 10 12 December 2016 Adrian Iftene adiftene@info.uaic.ro Recapitulation QoS Functional Testing Non-Functional Testing Rotting Design Refactoring 2 QoS = ability to provide different priority to different
More informationRefactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11. University of Colorado, 2011
Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken
More informationRefactoring. Section (JIA s) OTHER SOURCES
Refactoring Section 7.2.1 (JIA s) OTHER SOURCES Code Evolution Programs evolve and code is NOT STATIC Code duplication Outdated knowledge (now you know more) Rethink earlier decisions and rework portions
More informationSOFTWARE ENGINEERING SOFTWARE EVOLUTION. Saulius Ragaišis.
SOFTWARE ENGINEERING SOFTWARE EVOLUTION Saulius Ragaišis saulius.ragaisis@mif.vu.lt CSC2008 SE Software Evolution Learning Objectives: Identify the principal issues associated with software evolution and
More informationHow We Refactor, and How We Know It
Emerson Murphy-Hill, Chris Parnin, Andrew P. Black How We Refactor, and How We Know It Urs Fässler 30.03.2010 Urs Fässler () How We Refactor, and How We Know It 30.03.2010 1 / 14 Refactoring Definition
More informationCSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke
CSE 403 Lecture 21 Refactoring and Code Maintenance Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke slides created by Marty Stepp http://www.cs.washington.edu/403/
More informationCredit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture
Credit where Credit is Due Lecture 25: Refactoring Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some of the material for this lecture and lecture 26 is taken
More informationR E A D C L E A N C O D E : A H A N D B O O K O F S O F T W A R E C R A F T S M A N S H I P. C H A P T E R S 2 A N D 4.
R E A D C L E A N C O D E : A H A N D B O O K O F S O F T W A R E C R A F T S M A N S H I P. C H A P T E R S 2 A N D 4. H T T P S : / / R E F A C T O R I N G. G U R U / R E F A C T O R I N G / C A T A
More informationEvolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring
CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Refactoring April 24, 2007 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing Code 1 Evolving Software
More informationSmall changes to code to improve it
Small changes to code to improve it 1 Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior
More informationAdministrivia. Programming Language Fall Example. Evolving Software. Project 3 coming out Midterm October 28. Refactoring October 14, 2004
CMSC 433 Programming Language Fall 2004 Project 3 coming out Midterm October 28 Administrivia Refactoring October 14, 2004 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing
More informationRefactoring. Paul Jackson. School of Informatics University of Edinburgh
Refactoring Paul Jackson School of Informatics University of Edinburgh Refactoring definition Refactoring (noun) is a change made to the internal structure of software to make it easier to understand,
More informationCSCD01 Engineering Large Software Systems. Refactoring. Joe Bettridge. Winter With thanks to Anya Tafliovich (Based on Refactoring by M.
CSCD01 Engineering Large Software Systems Refactoring Joe Bettridge Winter 2018 With thanks to Anya Tafliovich (Based on Refactoring by M. Fowler) What is Refactoring? Process of changing a software system
More informationRefactoring. George Dinwiddie idia Computing, LLC
Refactoring George Dinwiddie idia Computing, LLC http://idiacomputing.com http://blog.gdinwiddie.com What is Refactoring? Refactoring is a disciplined technique for restructuring an existing body of code,
More informationRefactoring. Chen Tang March 3, 2004
Refactoring Chen Tang March 3, 2004 What Is Refactoring (Definition) Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationThe Benefits And Reasons for Doing Refactoring
The Benefits And Reasons for Doing Refactoring CSC508 Software Engineering by Magnus Aase December 11, 2001 The people behind the work of Refactoring seem all to agree on that Refactoring is not a cure
More informationChapter 9: Organizing Data
Chapter 9: Organizing Data In this chapter I ll discuss several refactorings that make working with data easier. For many people Self Encapsulate Field (185) will seem unnecessary. It s long been a matter
More informationRefactoring. Refactoring Techniques
Refactoring Refactoring Techniques Code Quality is Important! Refactoring is... A disciplined technique for restructuring an existing body of code, altering its internal structure without changing its
More informationHugbúnaðarverkefni 2 - Static Analysis
Time to do some refactoring of my Java. Hugbúnaðarverkefni 2 - Static Analysis Fyrirlestrar 7 & 8 A Refactoring Micro-Example 15/01/2006 Dr Andy Brooks 1 Case Study Dæmisaga Reference A Refactoring Micro-Example,
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationOverview of Eclipse Lectures. Module Road Map
Overview of Eclipse Lectures 1. Overview 2. Installing and Running 3. Building and Running Java Classes 4. Refactoring Lecture 2 5. Debugging 6. Testing with JUnit 7. Version Control with CVS 1 Module
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationRefactoring. What to refactor Refactor to what How to conduct the refactoring. This website is also very informative
Refactoring What to refactor Refactor to what How to conduct the refactoring This website is also very informative https://refactoring.com/catalog/ Definitions Changing/improving the code structure w/o
More informationJava Classes, Inheritance, and Interfaces
Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality
More informationProgramming overview
Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationChapter 15: A Longer Example
Chapter 15: A Longer Example Reading individual refactorings is important, because you have to know the moves in order to play the game. Yet reading about refactorings one at a time can also miss the point,
More informationENCAPSULATION AND POLYMORPHISM
MODULE 3 ENCAPSULATION AND POLYMORPHISM Objectives > After completing this lesson, you should be able to do the following: Use encapsulation in Java class design Model business problems using Java classes
More informationIndex. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107
A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105
More informationKeywords Code clean up, code standard, maintainability, extendibility, software refactoring, bad smell code.
Volume 7, Issue 5, May 2017 ISSN: 2277 128X International Journal of Advanced Research in Computer Science and Software Engineering Research Paper Available online at: www.ijarcsse.com A Review on Bad
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationRefactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11. University of Colorado, 2011
Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationPatterns in Software Engineering
Patterns in Software Engineering Lecturer: Raman Ramsin Lecture 10 Refactoring Patterns Part 1 1 Refactoring: Definition Refactoring: A change made to the internal structure of software to make it easier
More informationCollections. Collections. Collections - Arrays. Collections - Arrays
References: Beginning Java Objects, Jacquie Barker; The Java Programming Language, Ken Arnold and James Gosling; IT350 Internet lectures Collections Collection types Collection wrappers Composite classes
More informationLecture Notes. Polymorphism. Polymorphism. If Polymorphism is Not Available. To be placed at:
To be placed at: Lecture Notes www.cs.umb.edu/~jxs/courses/cs40 Polymorphism Polymorphism If Polymorphism is Not Available Customer gettotaltax():float * Account accounts # balance: float getbalance():
More informationCollections. Collections Collection types Collection wrappers Composite classes revisited Collection classes Hashtables Enumerations
References: Beginning Java Objects, Jacquie Barker; The Java Programming Language, Ken Arnold and James Gosling; IT350 Internet lectures 9/16/2003 1 Collections Collection types Collection wrappers Composite
More informationCS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?
CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look
More informationPASS4TEST IT 인증시험덤프전문사이트
PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from
More informationMSO Refactoring. Hans Philippi. October 2, Refactoring 1 / 49
MSO Refactoring Hans Philippi October 2, 2018 Refactoring 1 / 49 This lecture What is refactoring?... or how to deal with the horrible code your colleagues have created... or how to deal with the horrible
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More informationPrinciples of Object Oriented Programming. Lecture 4
Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming
More informationImplementing Subprograms
Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing
More informationCOMP 401 Spring 2014 Midterm 1
COMP 401 Spring 2014 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page
More informationSOFTWARE ENGINEERING. Lecture 4 CS2110 Spring 2013
1 SOFTWARE ENGINEERING Lecture 4 CS2110 Spring 2013 ... picking up where we stopped 2 We were discussing the class hierarchy We had been focused on extending a class by creating a new child class We looked
More information... picking up where we stopped SOFTWARE ENGINEERING. Interfaces 28/01/2013. Example: Overriding tostring. Example: Overriding tostring
1 picking up where we stopped 2 We were discussing the class hierarchy SOFTWARE ENGINEERING Lecture 4 CS2110 Spring 2013 We had been focused on extending a class by creating a new child class We looked
More informationChapter 15: Object Oriented Programming
Chapter 15: Object Oriented Programming Think Java: How to Think Like a Computer Scientist 5.1.2 by Allen B. Downey How do Software Developers use OOP? Defining classes to create objects UML diagrams to
More informationCSCE145 Test 2-Review 03/29/2015 Hongkai Yu
CSCE145 Test 2-Review 03/29/2015 Hongkai Yu 1. What results are printed when the main method in TestBase is executed? public class Base private int value; public Base(int x) value = x; System.out.println(
More informationOutline. 15. Inheritance. Programming in Java. Computer Science Dept Va Tech August D Barnette, B Keller & P Schoenhoff
Outline 1 Inheritance: extends ; Superclasses and Subclasses Valid and invalid object states, & Instance variables: protected Inheritance and constructors, super The is-a vs. has-a relationship (Inheritance
More informationMore C++ : Vectors, Classes, Inheritance, Templates
Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationLearn more about our research, discover data science, and find other great resources at:
Learn more about our research, discover data science, and find other great resources at: http://www.dataminingapps.com Chapter 7 Delving Further into Object- Oriented Concepts Overview Annotations Overloading
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationCS 113 PRACTICE FINAL
CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you
More informationThe Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000
The Object Class Mark Allen Weiss Copyright 2000 1/4/02 1 java.lang.object All classes either extend Object directly or indirectly. Makes it easier to write generic algorithms and data structures Makes
More informationMore C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com
More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes
More informationCOURSE 2 DESIGN PATTERNS
COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract
More information1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8
Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationObject-Oriented Programming
Object-Oriented Programming - Encapsulation Data & code bound together - > objects - Polymorphism Overloading of constructors & methods - Inheritance A class incorporates another class into its declaration
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationObject Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse
Object-Oriented Design Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented Design 1 March 2005 Object Oriented
More informationbright code, dull code by fox \
bright code, dull code by fox peterson @a_fox_box \ Can you think of a time you ve been here? You come across a piece of code, you are expected to be able to work with it, and you re thinking I DIDN T
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationAbsolute C++ Walter Savitch
Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents
More informationI BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++
No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)
More informationTutorial 02: Writing Source Code
Tutorial 02: Writing Source Code Contents: 1. Generating a constructor. 2. Generating getters and setters. 3. Renaming a method. 4. Extracting a superclass. 5. Using other refactor menu items. 6. Using
More informationG51PGP Programming Paradigms. Lecture OO-4 Aggregation
G51PGP Programming Paradigms Lecture OO-4 Aggregation 1 The story so far We saw that C code can be converted into Java code Note real object oriented code though Hopefully shows you how much you already
More informationInheritance (Part 5) Odds and ends
Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there
More informationMore about inheritance
Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting
More informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More informationObject-Oriented Design. March 2005 Object Oriented Design 1
Object-Oriented Design March 2005 Object Oriented Design 1 Object Oriented Design Goals Robustness Adaptability Flexible code reuse Principles Abstraction Encapsulation Modularity March 2005 Object Oriented
More informationBasic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems
Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction
More informationCS 1302 Chapter 9 (Review) Object & Classes
CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state
More informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationCOMP200 - Object Oriented Programming: Test One Duration - 60 minutes
COMP200 - Object Oriented Programming: Test One Duration - 60 minutes Study the following class and answer the questions that follow: package shapes3d; public class Circular3DShape { private double radius;
More informationComp-304 : Object-Oriented Design What does it mean to be Object Oriented?
Comp-304 : Object-Oriented Design What does it mean to be Object Oriented? What does it mean to be OO? What are the characteristics of Object Oriented programs (later: OO design)? What does Object Oriented
More informationInheritance. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Supplementary Examination Question
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationSoftware Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 15/06/2011
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2011 Thorsten Joachims Lecture 7: Software Design Software Engineering The art by which we start with a problem statement and gradually
More informationF. Tip and M. Weintraub REFACTORING. Thanks go to Andreas Zeller for allowing incorporation of his materials
F. Tip and M. Weintraub REFACTORING Thanks go to Andreas Zeller for allowing incorporation of his materials TODAY S LECTURE anti-patterns common response to a recurring problem that is usually ineffective
More informationProgramming Exercise 14: Inheritance and Polymorphism
Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.
More information