Upload
theodora-pearson
View
217
Download
2
Tags:
Embed Size (px)
Citation preview
CSE 222: Software Components in Engineering (SCE) – Introduction
Instructor: Jimmy VossDisclaimer: Not all material is original. Some
is taken from the official course slides, and some is taken from Anna’s slides.
Syllabus Information
• Course Coordinator: Dr. Bruce Weide• Instructor: Jimmy Voss– E-mail: [email protected]– Office: 407 Caldwell– Office Hours: 2:30 – 3:30 Tu Th
• Course website:– http://www.cse.ohio-state.edu/sce/now/222/
Overview of Course
• Use RESOLVE/C++ to teach programming concepts and software engineering principles:– Use of data structures– Client View and Implementer’s View– Design by contract– Memory management / pointers– Data structure implementations
What is RESOLVE/C++?
• An approach to programming in C++• Uses formal comments to specify precise
program behavior.• Implemented using macros, classes, and
formal comments.• Implements a set of template libraries.• Implements 4 standard operations for all
components.
Review of Resolve
• Combines a programming language (C++) and a specification language.– For code to be correct, it must work precisely
when the specifications are met.– Use formal comments for specifications.– Some specifications described via keywords which
have no meaning in C++.• Disciplined way of programming C++
Review of Resolve
• All Resolve components are classes with 4 predefined operations:– Swap -- denoted &=– Constructor– Destructor– Clear member function
Sequence -- A Resolve/C++ component
• a sequence is an ordered grouping of objects– Example: “abc” is an ordered sequence of
characters. A Text object could be used.• Sequence – the Abstract RESOLVE/C++
component:– 4 operations allowed:
• Add( pos, x )• Remove( pos, x )• Accessor, i.e., [pos]• Length()
Instantiating Sequence
#include "RESOLVE_Foundation.h"
#include "CT/Sequence/Kernel_1a_C.h"
concrete_instanceclass Sequence_Of_Integer : instantiates Sequence_Kernel_1a_C <Integer>{};
Instantiating Sequence
#include "RESOLVE_Foundation.h"
#include "CT/Sequence/Kernel_1a_C.h"
concrete_instanceclass Sequence_Of_Integer : instantiates Sequence_Kernel_1a_C <Integer>{};
Preprocessor directives
RESOLVE Keyword
Template parameter
Preprocessor directives
• #include– Used to include the contents of another file at the current
location in the current file.– Example:
• #include "RESOLVE_Foundation.h"
• #define– Used for text replacement which occurs before the
program is compiled.– Examples:
• #define concrete_instance• #define procedure_body virtual void
Template parameters
• Template parameter – a token which represents a type name.
• Classes and functions can be defined on arbitrary types. To use such classes / functions, the user must supply the template parameter.
• Container classes such as Sequence require a template parameter to be instantiated.
• In this course, we instantiate template parameters via inheritance.
Inheritance and templating
• Inheritance takes on the form:class child : instantiates parent
• The child class contains all member functions and variables of the parent class.
• If the parent class has requires a template parameter, then a new class with the template parameter filled in is created via:
parent< template_type >
• Note: This is not the only way of filling in template parameters.
Instantiating Sequence
#include "RESOLVE_Foundation.h"
#include "CT/Sequence/Kernel_1a_C.h"
concrete_instanceclass Sequence_Of_Integer : instantiates Sequence_Kernel_1a_C <Integer>{};
Preprocessor directives
RESOLVE Keyword
Template type parameter
FormalComment /the contract
Pass by reference
An Example (Continued)global_procedure Smooth( preserves Sequence_Of_Integer & s1, produces Sequence_Of_Integer & s2)/*! ... !*/{ // s2 is produces mode and should not depend on // the input. s2.Clear();
object Integer Index = 0; while ( Index < s1.Length() - 1 ) { s2.Add( Index, (s1[Index] + s1[Index+1]) / 2 ); }}
Set
• Set – A set is an unordered collection of objects which contain no duplicates.
• Examples of sets:– {1, 2, 3, 4, 5}– {}– {“Bob”, “the cat”, “Tom”, “Random string”}
• Not a set:– {0, 0, 1, 2}
Requires: x self
Requires: x self