11. Kehysarkkitehtuurit Johdanto Kehystyypit Kehykset ja arkkitehtuuri Kehykset ja suunnittelumallit Kehyspohjainen ohjelmistokehitys 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
Sovellusalue: videopelit Perinteinen Liiketoimintanäkökulma kulma 1. peli 2. peli 3. peli työtuntia 0 100 200 300 400 500 600 700 800 900 Kehykseen perustuva Kehyksen rakentaminen + koulutus 1. peli 2. peli 3. peli Suorituskyky: aika +70% tila +200% 5
Erikoistamistekniikat kehyksissä rajapinnan toteutus periytyminen olioiden/komponenttien luonti, alustus ja konfigurointi geneeristen rakenteiden (esim. geneeriset luokat) instantiointi refleksiivisyys 6
Kehystyypit Erikoistamisen tulos Sovelluskehys: erikoistamisen tulos on sovellus Komponenttikehys (framelet): erikoistamisen tulos on komponentti Hierarkkinen kehys: erikoistamisen tulos on uusi kehys Erikoistamismekanismi 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 7
Muunneltavat kehykset A B 8
Koottavat kehykset A B <<create>> 9
Plugin-kehykset rajapintoja komponentteja 10
Kehykset ja arkkitehtuuri Kehyksen dekompositio: käsitemallipohjainen lähestymistapa Kehyksen dekompositio: komponenttipohjainen lähestymistapa Kehyksen kerrostaminen: hierarkkiset kehykset 11
Käsitemallipohjainen lähestymistapal OO-arkkitehtuurityyli : 1) Tee sovellusalueen käsitemalli 2) Hae ja lisää käsitemalliin yleistykset (kantaluokat) 3) Muunna käsitemalli luokkamalliksi 4) Tunnista variaatiopisteet luokkamallista 5) Suunnittele variaatiopisteiden toteutus (suunnittelumallit) 12
Esimerkki: Simulointikehys 13
<<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 <<create>> DefaultCreatureFactory xcoord ycoord age setmyworld(world)... die() <<create>> createcreature(): Creature EatingCreature energy interact(creature) SimulationApp main() <<create>> <<create>> EatingCreatureFactory createcreature(): Creature 14
<<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) <<create>> <<interface>> CreatureFactory 1 createcreature(): Creature DefaultCreatureFactory DefaultCreature xcoord ycoord age setmyworld(world)... die() EatingCreature energy interact(creature) <<create>> <<create>> createcreature(): Creature EatingCreatureFactory createcreature(): Creature SimulationApp <<create>> main() 15
<<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) <<create>> EatingCreatureFactory createcreature(): Creature 16
Komponenttipohjainen lähestymistapa: l Monoliittiset kehykset vs. frameletit Monoliittinen kehys Sovellus Kehys Framelet Framelet Komponentti Komponentti Erikoistus Erikoistus Erikoistus 17
Hierarkkinen kehys 18
Hierakkinen kehys kerrosrakenne Punamuurahaisten simulointisovellus Muurahaisten simulatointikehys Hyönteisten simulointikehys Eläinpopulaatioiden simulointikehys Yleinen simulointikehys 19
Hierakkinen kehys kerrosrakenne Verkonhallintasovellus Verkonhallintasovelluskehys Swing AWT 20