Title: IEG3080 Software Engineering
1IEG3080 Software Engineering
- Instructor Prof. Michael Chang
- About this course
- Object-oriented programming
- C
- Design Patterns
- Software Methodologies
- Reference text
- Design patterns by Gamma et al (Addison Wesley)
- The Bible in OO, must read it if you are
interested in OO. Examples written in C, but
not hard to follow - www.wikipedia.org
2- 4 Assignment 10
- 1 Project 30
- Final Exam (open notes, one A4 paper) 60
- Homepage http//course.ie.cuhk.edu.hk/ieg3080
- How to download Visual Studio .NET
- Get the form from
- www.ie.cuhk.edu.hk/fileadmin/download/student/docu
ment/msdnaa.pdf - Ignore the CD part, dont need my signature, sign
it and return it to tutors
3- No plagiarism
- Policy of zero tolerance
- Penalties include failing the course and
receiving demerits. - http//www.cuhk.edu.hk/policy/academichonesty/
- Please sign the No plagiarism declaration form
and attach it together with your
assignment/project - The form can be downloaded from section 9 in
above site
4 5What is software engineering?
- How to build
- large-scale software
- by a large team of people
- quickly
- and
- inexpensively?
6Problems
- Software is expensive
- Delivery is always late
- Software is unreliable
- Software is difficult to maintain
- the code is written by other people
- Software is difficult to adapt to future change
- Difficult to manage a large team
7Problems
- Technical problems
- To build complex software reliably, quickly,
cheaply, easy to maintain, and can be changed
flexibly in future - OO, design patterns, etc
- Management problems
- How to manage software project
- Software methodology
8Management solution
- Effective communication
- How to manage a team
- People has different skills
- Turnover
- Communicate in a large team
- Quality of the software
- How to manage the customers
- How to collect the requirements
- Are we building the system that the customers
want?
9Management solution
- Software methodologies
- Best practices in software development
- Traditional methods
- Rational Unified Process
- Extreme Programming (XP)
- CASE tools
- UML - schematic diagram for software
- NUnit for regression testing of software
10Technical solution
- How to build complex software reliably, quickly,
cheaply, easy to maintain, and can be changed
flexibly in future - Solution
- Reusable software
- Key to reusable software
- Many solutions, but the most important concept is
the interface - In particular, the separation of interface with
the implementation
11Levels of reuse
- Source code reuse
- But vendors dont give the source code away
- Binary code reuse
- But how to modify existing binary code?
- Interface reuse
- Key to flexible software
- Design reuse
- Design patterns, solutions to common programming
problems
12Software is complex
- How to deal with complex system?
- Divide and conquer
- Divide a complex system into sub-systems, and a
sub-system into objects - Each component can be developed independently
from each other - How to divide a system into parts
- Key issue - the interface between parts
13????
14To divide a system into parts
Body
Head
Read Leg
Front Leg
15Is software easy to change?
- Good software will be used for many years
- Must be able to extend/modify the software in
order to cater for future needs - Is software easy to change?
- Look easy, but in fact difficult !!
- Why?
- Too many dependencies between different modules
- ???????
16Solution?
- Reduce dependency between parts
- Can change a component freely without affecting
the rest of the system - Interface is the key to flexible and extensible
software - Related concepts
- Loose coupling
- Modularity
- Encapsulation
- Information hiding
17Interface so that parts can be changed
independently
PC
Camera
USB Interface
Disk
Phone
18To connect to a new camera
New Camera
PC
USB Interface
Disk
Phone
19Interface and Implementation
- Interface is a specification, describing how
components should be joint - Implementation is the real stuff (the code)
- Interface is MORE IMPORTANT than implementation
- Why?
- Interface, once fixed, is hard to change
- e.g. USB
- Implementation can be easily changed
- e.g. mobile phone, camera, printer
20What is an object?
- Object is a software component that you can reuse
easily - Each object has its own localized functions and
data - Object function data
- Why do we want localized functions and data?
- So that we can change a component easily
New Camera (data)
PC (data)
21Separation of interface and implementation
- Interface and implementation are two different
things
New Camera (data)
PC (data)
Implementation
Interface (USB)
22What is a USB interface?
- Just a specification on paper
- Abstract concept, not concrete product
- Interface, not implementation
23What is the use of header file in C?
Interface
implementation
.h file int foo(int x)
.c file int foo(int x) . . .
24The reason of using header file
- Separation of interface and implementation
.h file
Rest of the system Can only see the header file,
so that the implementation can be changed freely
.c file
25The advantage of the separation
- .c file (the code) can be changed without
affecting the rest of the system - .h file (the header) cannot be changed!!
.h file
Rest of the system Can only see the header file,
so that the code can be changed freely
New .c file
26The essential idea of OO
- Base class provides the interface (function
declaration) - The subclass provides the function implementation
- The subclass inherits the interface of the base
class
Interface class
Rest of the system Can only see the base class
(interface), so that the subclass (implementation)
can be changed freely
Implementation
27Inheritance
- Inheritance is a key concept in OOP. What does it
mean? - If class B inherits class A, then class B has
everything in A - Class interface implementation
- An easy way to reuse other peoples interface and
implementation - UML notation
A
B
28Interface inheritance versus implementation
inheritance
- Class A (the base class) may have interface and
implementation -
- Class B (the sub-class) inherits both the
interface and implementation in A - Interface inheritance
- Implementation inheritance
- Interface inheritance is much more important than
implementation inheritance - The main purpose of the base class is to provide
an interface, so that the sub-class
(implementation) can be changed freely in future
29Reusable software
- Inheritance reuse
- By inheritance
- Implementation reuse
- By delegation
- Reuse other peoples code by using other peoples
object to do the work for you - Inheritance and delegation are the two key
concepts in OO
30Common misconception about OO
- Wrong concept
- The main purpose of inheritance is to inherit the
codes in the base class - This concept is wrong
- It confuses the concept of interface inheritance
with implementation inheritance - Implementation can be reused by delegation rather
than by inheritance - Just creates an object and use it (like getting a
code library and use it)
31Inheritance
- Example
- Interface
- USB specification (just a piece of paper, totally
abstract) - Implementation
- MP3 player
- Digital camera
- Mobile phone
-
32Inheritance and implementation
Rest of the System
USB
Interface
Mobile Phone
Implementation
MP3
Digital Camera
33Interface and implementation
- Interface promotes the following related design
concepts - Modularity
- Divide a system into modules
- Encapsulation
- Hide the complexity of module, expose only the
interface - Abstraction
- Intellectual simplification, e.g. USB is an
abstraction of devices (existing or yet to be
invented) - Reduce the amount of learning
- Loose coupling
- change in one module wont affect others
34The key to LARGE SCALE DEVELOPMENT
- Different parts are manufactured by different
companies from different places in the world - Modularity, encapsulation, abstraction, and loose
coupling are boiled down to one important
principle in good engineering design - The Interface
35Example of good interface
- World-wide web
- Network level interface HTTP protocol
- Human level interface HTML/XML
- Internet
- Interfaces - IP
- Airplane, plumbing, car, . . .
- 2nd language (English) is more important than
mother tongue for business communication
36The high input impedance / low output impedance
principle in circuit design
- B has high input impedance and low output
impedance, can change B without affecting the
rest of the system - Essential ideas are the same
- Divide and conquer
- With good interface, one can change a part
without affecting the rest of the system
Box A
Box B
Box C
37The most important principle in (software)
engineering
- Separation
- of
- Interface
- and
- Implementation
38Interface and implementation
Interface versus implementation
Disk drive CDROM Printer Digital
camera Future products . . .
USB bus
Polymorphism many different forms
39- USB is an abstraction of the hardware
- Design the PC system around the USB interface,
not to a particular device - The first principle in OOP (in Gammas Design
Pattern) -
- programming to an interface, not an
implementation
40From C, C to Java/C
- Basic principles are the same
- The separation of interface from implementation
- The differences
- On granularity
- C at sub-system level (coarser scale)
- C, C - at object level (finer scale)
- C is complicated
- C (and Java) is simpler (no pointer)
41Abstract versus concrete
- Interface is abstract, implementation is concrete
- Top designers design the interface, they dont
code !! - Implementation is done by programmers working
independently all over the world - OO is about an abstract style of programming,
focus on the interface
42Which one is a more successful design from OO
point of view?
Morning ?
Twins