Download presentation
Presentation is loading. Please wait.
Published byJoseph Richard Modified over 9 years ago
2
1 Craig Rasmussen Advanced Computing Laboratory Los Alamos National Laboratory Introduction to Object- and Component-Oriented Programming
3
2 Why Use Components? Promote software reuse – “The best software is code you don’t have to write” [Steve Jobs] Reuse, through cost amortization, allows –thoroughly tested code –highly optimized code –developer team specialization Hero programmer producing single-purpose, monolithic, tightly-coupled parallel codes Rob X
4
3 An Object Is … A software black box Contains data –data is normally hidden from users –“tall fences make good neighbors” Provides information based on its data –via a method (function) A class is software (code) defining an object –many object instances can be created from one class ClassName methods attributes
5
4 A CCA Component Is … A software black box Contains data –uses port –specifies required connections to other components –function caller –plus other data Provides information based on its data –provides port –function callee Consumer uses Producer provides
6
5 What’s the Difference? More similar than different –Objects + Components can discover information about the environment –from framework –from connected components Interface discovery –find provides ports –find uses ports –insure that connection can be made between two components Easily convert from an object orientation to a component orientation –automatic tools can help with conversion
7
6 Classes RandomGenerator random_value( ) Integrator integrate( ) Function value_at_x( )
8
7 Interface Declaration Integrator class Integrator { virtual void integrate( ) = 0; }; Integrator.h MODULE IntegratorModule interface integrate module procedure random_integrate end interface END MODULE Integrator.f90 integrate( )
9
8 Inheritance TrapezoidalIntegrator integrate( ) setFunctionInstance( ) FunctionInstance* MonteCarloIntegrator integrate() setFunctionInstance( ) setRandomGeneratorInstance( ) RandomGeneratorInstance* Integrator integrate( )
10
9 Object-Oriented Program #include #include "Function.h" #include "Integrator.h" #include "RandomGenerator.h" int main(int argc, char* argv[]) { LinearFunction* function = new LinearFunction(); UniformRandomGenerator* random = new UniformRandomGenerator(); MonteCarloIntegrator* integrator = new MonteCarloIntegrator(); integrator->setFunction(function); integrator->setRandomGenerator(random); cout integrate(100) << endl; return 0; }
11
10 Component Program LinearFunction value_at_x( ) UniformRandomGenerator random_value( ) MonteCarloIntegrator integrate( ) TrapezoidalIntegrator integrate( ) ReallyWierdFunction value_at_x( ) GaussianQuadIntegrator integrate( ) LinearNRandomGenerator random_value( ) Component LibraryProgram
12
11 Demonstration
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.