Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.

Slides:



Advertisements
Similar presentations
Revealing the Secrets of Self-Documenting Code Svetlin Nakov Telerik Corporation For C# Developers.
Advertisements

Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Unit 6 Assignment 2 Chris Boardley.
Comp1004: Building Better Classes II Software Design Partly based on BlueJ Book – Chapter 7.
Copyright by Scott GrissomCh 7 Designing Classes Slide 1 Well Designed Classes (Ch 7) Applications are a collection of interacting classes Our Goal It.
Lesson-06 Designing classes
Improving structure with inheritance Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Software Engineering and Design Principles Chapter 1.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 4.0.
Improving structure with inheritance
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
CM10134-CM50147 Programming I Basic Programming in Java Marina De Vos.
Objects First with Java A Practical Introduction using BlueJ
String Concatenation (operator overloading) 3.0.
Designing Classes How to write classes in a way that they are easily understandable, maintainable and reusable.
Well-behaved objects Improving your coding skills 1.0.
Grouping Objects 1 Introduction to Collections.
Design: Coupling and Cohesion How to write classes in a way that they are easily understandable, maintainable and reusable.
Make Sure You Know All This!. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 2 Objects and Classes.
STREAM STREAM A software process The Mañana Principle The Mañana Principle Don’t try to everything at once! Static Methods Static Methods Stateless Utility.
1 Teaching OOP - A Practical Approach using BlueJ Teaching OOP  A Practical Approach Using BlueJ David J Barnes University of Canterbury Michael Kölling.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Software maintenance Managing the processes of system change.
Test-Driven Development “Test first, develop later!” –OCUnit.
Lilian Blot Announcements The TPOP problem class this afternoon:  group 1 should come at 3.30pm and group 2 at 4pm. Teaching Evaluation Form  week 9.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
Objects First With Java A Practical Introduction Using BlueJ Designing applications 1.0.
Improving structure with inheritance Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables Objects First with Java.
Improving structure with inheritance Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables Objects First with Java.
SE: CHAPTER 7 Writing The Program
Improving the Quality of Existing Code Svetlin Nakov Telerik Corporation
Designing Classes 2 How to write classes in a way that they are easily understandable, maintainable and reusable.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Software Testing and Maintenance 1 Code Review  Introduction  How to Conduct Code Review  Practical Tips  Tool Support  Summary.
Software Engineering Principles. SE Principles Principles are statements describing desirable properties of the product and process.
Designing applications Main concepts to be covered Discovering classes CRC cards Designing interfaces Patterns Objects First with Java - A Practical.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
1 COS 260 DAY 14 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz graded  Oct 29 –Chapter 6 Assignment 4 will be posted later Today –First two problems.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 6.0.
Coupling and Cohesion Schach, S, R. Object-Oriented and Classical Software Engineering. McGraw-Hill, 2002.
Review. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Objects and Classes Objects and Classes –State.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
Objektorienterad programmering d2, förel. 8
DESIGNING CLASSES THE GAME OF LIFE
Data Abstraction: The Walls
Objects First with Java
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java
COS 260 DAY 11 Tony Gauvin.
Programming Logic and Design Fourth Edition, Comprehensive
Exercise 1 Declare a constant of type int called SIZE and initialize it to value 10 Declare two int arrays of size “SIZE” Assume that those int arrays.
Objects First with Java A Practical Introduction using BlueJ
Objektorienterad programmering d2, förel. 8
COS 260 DAY 14 Tony Gauvin.
Objects First with Java A Practical Introduction using BlueJ
Improving structure with inheritance
Chapter 9: Implementation
Presentation transcript:

Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 1.0

2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to be covered Responsibility-driven design Coupling Cohesion Refactoring

3 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained, ported, adapted… The work is done by different people over time (often decades).

4 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Change or die There are only two options for software: –Either it is continuously maintained –or it dies. Software that cannot be maintained will be thrown away.

5 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling World of Zuul

6 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Code quality Two important concepts for quality of code: Coupling Cohesion

7 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Coupling Coupling refers to links between separate units of a program. If two classes depend closely on many details of each other, we say they are tightly coupled. We aim for loose coupling.

8 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Loose coupling Loose coupling makes it possible to: understand one class without reading others; change one class without affecting others. Thus: improves maintainability.

9 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Cohesion Cohesion refers to the the number and diversity of tasks that a single unit is responsible for. If each unit is responsible for one single logical task, we say it has high cohesion. Cohesion applies to classes and methods. We aim for high cohesion.

10 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling High cohesion High cohesion makes it easier to: understand what a class or method does; use descriptive names; reuse classes or methods.

11 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Cohesion of methods A method should be responsible for one and only one well defined task.

12 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Cohesion of classes Classes should represent one single, well defined entity.

13 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Code duplication is an indicator of bad design, makes maintenance harder, can lead to introduction of errors during maintenance.

14 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Responsibility-driven design Question: where should we add a new method (which class)? Each class should be responsible for manipulating its own data. The class that owns the data should be responsible for processing it. RDD leads to low coupling.

15 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Localizing change One aim of reducing coupling and responsibility-driven design is to localize change. When a change is needed, as few classes as possible should be affected.

16 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Thinking ahead When designing a class, we try to think what changes are likely to be made in the future. We aim to make those changes easy.

17 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Refactoring When classes are maintained, often code is added. Classes and methods tend to become longer. Every now and then, classes and methods should be refactored to maintain cohesion and low coupling.

18 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Refactoring and testing When refactoring code, separate the refactoring from making other changes. First do the refactoring only, without changing the functionality. Test before and after refactoring to ensure that nothing was broken.

19 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Design questions Common questions: How long should a class be? How long should a method be? Can now be answered in terms of cohesion and coupling.

20 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Design guidelines A method is too long if it does more then one logical task. A class is too complex if it represents more than one logical entity. Note: these are guidelines - they still leave much open to the designer.

21 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Review Programs are continuously changed. It is important to make this change possible. Quality of code requires much more than just performing correct at one time. Code must be understandable and maintainable.

22 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Review Good quality code avoids duplication, displays high cohesion, low coupling. Coding style (commenting, naming, layout, etc.) is also important. There is a big difference in the amount of work required to change poorly structured and well structured code.