8. Kehysarkkitehtuurit Johdanto Kehystyypit Esimerkki: Simulointikehyksen malleja Kehyspohjainen ohjelmistokehitys Kehykset ja suunnittelumallit Esimerkkikehys Kehysten toteutuksesta Kehysten etuja ja ongelmia Yhteenvetoa 1
Johdanto Mikä on (ohjelmisto)kehys? Ohjelmistokehys on standardi olioparadigman tapa toteuttaa tuotealusta. Kehys muodostuu kokoelmasta luokkia, jotka toteuttavat tuoteperheen yhteisen arkkitehtuurin ja toiminnallisuuden. Kehys erikoistetaan tuotteeksi. 2
Kehys erikoistetaan toimivaksi tuotteeksi Kehys Sovelluskohtainen koodi kontrolli Erikoistamisrajapinta 3
Sovelluskehys vs. perinteinen ohjelmakirjasto: Hollywood-periaate Aliluokkia, komponentteja Sovelluskohtainen Sovellus Uudelleenkäytettävä Sovelluskehys Aliohjelmia, luokkia, moduuleita Hollywood-periaate: Älä soita meille, me soitetaan teille 4
Erikoistamistekniikat kehyksissä rajapinnan toteutus periytyminen olioiden/komponenttien luonti, alustus ja konfigurointi geneeristen rakenteiden (esim. luokka) instantiointi refleksiivisyys 5
Kehystyypit Sovelluskehys: erikoistamisen tulos on sovellus Komponenttikehys (framelet): erikoistamisen tulos on komponentti Hierarkkinen kehys: erikoistamisen tulos on uusi kehys Muunneltava kehys: erikoistaminen tehdään lähinnä periytymisellä Koottava kehys: erikoistaminen tehdään lähinnä instantioinnilla Plugin-kehys: erikoistaminen tehdään lähinnä rajapintojen toteutuksella 6
Muunneltavat kehykset A B 7
Koottavat kehykset A B 8
Plugin-kehykset rajapintoja komponentteja 9
Monoliittiset kehykset vs. frameletit Monoliittinen kehys Sovellus Kehys Framelet Framelet Erikoistus Komponentti Komponentti Erikoistus Erikoistus 10
Hierarkkinen kehys 11
Hierakkinen kehys sovellusten kerrosrakenne Punamuurahaisten simulointisovellus Muurahaisten simulatointikehys Hyönteisten simulointikehys Eläinpopulaatioiden simulointikehys Yleinen simulointikehys 12
Hierakkinen kehys sovellusten kerrosrakenne Verkonhallintasovellus Verkonhallintasovelluskehys Swing AWT 13
Esimerkki: Simulointikehyksen malleja 14
<<framework>> SimulationFW Muunneltava (white-box) kehys <<interface>> Creature setmyworld(world) show() getx(): int gety(): int move() interact(creature) growold() die() * World getsize(): int add(creature) remove(creature) show() simulate(int, CreatureFactory) <<interface>> CreatureFactory 1 createcreature(): Creature DefaultCreature DefaultCreatureFactory xcoord ycoord age setmyworld(world)... die() createcreature(): Creature EatingCreature energy interact(creature) SimulationApp main() EatingCreatureFactory createcreature(): Creature 15
<<framework>> SimulationFW Koottava (black-box) box) kehys <<interface>> Creature setmyworld(world) show() getx(): int gety(): int move() interact(creature) growold() die() * World getsize(): int add(creature) remove(creature) show() simulate(int,creaturefactory) <<interface>> CreatureFactory 1 createcreature(): Creature DefaultCreatureFactory DefaultCreature xcoord ycoord age setmyworld(world)... die() EatingCreature energy interact(creature) createcreature(): Creature EatingCreatureFactory createcreature(): Creature SimulationApp main() 16
<<framework>> SimulationFW <<interface>> Creature setmyworld(world) show() getx(): int gety(): int move() interact(creature) growold() die() * World getsize(): int add(creature) remove(creature) show() simulate(int,creaturefactory) Plug-in kehys 1 PluginLoader <<interface>> CreatureFactory createcreature(): Creature load() <<load>> <<plugin>> EatingApplication EatingCreature SimulationApp energy main() interact(creature) EatingCreatureFactory createcreature(): Creature 17