Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,

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.
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
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
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
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.
Object-Oriented Metrics. Characteristics of OO ● Localization ● Encapsulation ● Information hiding ● Inheritence ● Object abstraction.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
A Brief Introduction to Software Design and Design Quality By Laura Leventhal.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
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.
Design: Coupling and Cohesion How to write classes in a way that they are easily understandable, maintainable and reusable.
Object-Orientated Design Unit 3: Objects and Classes Jin Sa.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
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 9 – Software Evolution and Maintenance
1 EECS 231 ADVANCED PROGRAMMING. 2 Staff Instructor Vana Doufexi Ford Building, 2133 Sheridan, #2-229 Teaching Assistant.
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.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Systems Analysis and Design in a Changing World, Fifth Edition
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
CSE 303 – Software Design and Architecture
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 3.0.
CSC 395 – Software Engineering Lecture 12: Reusability –or– Programming was Bjarne Again.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
SE: CHAPTER 7 Writing The Program
Component Technology. Challenges Facing the Software Industry Today’s applications are large & complex – time consuming to develop, difficult and costly.
Cohesion and Coupling CS 4311
Systems Analysis and Design in a Changing World, 3rd Edition
Designing Classes 2 How to write classes in a way that they are easily understandable, maintainable and reusable.
Designing classes How to write classes in a way that they are easily understandable, maintainable and reusable 5.0.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
Program Style Chapter 22 IB103 Week 12 (part 2). Modularity: the ability to reuse code Encapsulation: hide data access directly but may use methods (the.
Dr D. Greer, Queens University Belfast )Chapter Six 1 Software Engineering Chapter Six Software Design Quality Learning Outcomes.
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.
Or how to work smarter when building solutions.  2:30 – 3:30 Mondays – focus on problem solving (with some terminology thrown in upon occasion)  All.
Refactoring Agile Development Project. Lecture roadmap Refactoring Some issues to address when coding.
Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.
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.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Chapter 10 Software quality. This chapter discusses n Some important properties we want our system to have, specifically correctness and maintainability.
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.
Coupling and Cohesion Pfleeger, S., Software Engineering Theory and Practice. Prentice Hall, 2001.
Object-Orientated Analysis, Design and Programming
Objektorienterad programmering d2, förel. 8
Data Abstraction: The Walls
Objects First with Java
The Object Oriented Approach to Design
Objects First with Java
Programming Logic and Design Fourth Edition, Comprehensive
Software Design Lecture : 8
Objektorienterad programmering d2, förel. 8
COS 260 DAY 14 Tony Gauvin.
Object-Oriented PHP (1)
Information Hiding and Encapsulation Section 4.2
Presentation transcript:

Designing Classes

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).

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.

It is possible to implement an application and to get it to perform its task with badly designed classes. Just executing a finished application does not usually indicate whether it is structured well internally or not. Code quality

Two important concepts for quality of code: Coupling Cohesion

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. –Each class is largely independent and communicates with other classes via a small, well defined interface

Loose coupling Loose coupling makes it possible to: understand one class without reading others; change one class without affecting others. Thus: improves maintainability.

Cohesion Cohesion refers to 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. –A class should represent one type of entity. –A method should implement one logical operation. We aim for high cohesion.

High cohesion High cohesion makes it easier to: understand what a class or method does; use descriptive names; reuse classes or methods.

Code Duplication Having the same segment of code in an application more than once. An indicator of bad design and should be avoided Code duplication makes application maintenance difficult. Usually a symptom of low cohesion

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.

Encapsulation The encapsulation guideline is hiding information from view. Only information about what a class can do should be visible to the outside, not how it does it. Enforce this separation of what and how by making the fields private, and using accessor methods to access them.

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.

Refactoring The activity of restructuring an existing design to maintain a good class design when the application is modified or extended.

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.

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.

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.

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.

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.