1 / 23

Component-Based Programming Paradigm: Benefits and Challenges

Explore component architecture, late integration, component principle, and source code redundancy in program design and development. Learn about the advantages and disadvantages of the component paradigm.

umika
Download Presentation

Component-Based Programming Paradigm: Benefits and Challenges

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generikus Programszerkezetek • Nagy István <nagyist@delfin.klte.hu> • Vég Csaba<vega@dragon.klte.hu> KLTE

  2. Komponens paradigma • Technológiai szempont: • late integration • komponens-architektúra (wiring) • a használat előtérbe helyeződése(funkcionális-csomópontok) • az elemek funkciókon keresztül kezelhetők (nem pedig közvetlenül) • Komponens: “Szaktudáskonzerv”

  3. Komponens-elv (absztrakció) • Komponens-elv a tervezésben és programozásban • adott (nem tetszőleges) módon programozunk • attribútumok helyett tulajdonságok (property)(olvasó/író metódusok) • elnevezések • elemek elrendezése • „szabvány” szerinti forma, tapasztalat közvetlen megszerzése • könnyebben értelmezhető, struktúrája könnyebben azonosítható • könnyebben módosítható

  4. abstract class Text max(): int length(): int read(pos:int) write(pos: int, ch: char) caretPos(): int setCaret(pos:int) delete(pos:int) type(ch:char) rubout() getMaximumLength(): int getLength(): int getCharacter(pos:int): char insertCharacter(pos:int, ch:char) getCaretPos(): int setCaretPos(pos:int) removeCharacter(pos:int) insertCharacter(ch:char) ruboutCharacter()

  5. abstract class Text getMaximumLength(): int getLength(): int getCharacter(pos:int): char insertCharacter(p:int, c:char) getCaretPos(): int setCaretPos(pos:int) removeCharacter(pos:int) insertCharacter(ch:char) ruboutCharacter() getCaretPos(): int setCaretPos(pos:int) getMaximumLength(): int getLength(): int setLength(l:int) getCharacter(pos:int): char getCharacter(): char setCharacter(pos:int, ch: char) setCharacter(ch: char) insertCharacter(pos:int, ch:char) insertCharacter(ch:char) removeCharacter(pos:int) removeCharacter() ruboutCharacter()

  6. A „nyelvek túl flexibilisek” • Feleslegesen sok lehetőséget engednek meg • A komponens elv egy bevált és jól működő változatot határoz meg • De: redundancia a forrásban!

  7. Redundancia /** The alpha property */ private int alpha; /** get method for property alpha */ public int getAlpha() { return alpha; } /** set method for property alpha */ public void setAlpha(int alpha_) { alpha=alpha_; }

  8. Redundancia Copy & Paste ? /** The alpha (double) property */ private double cacheOfAlpha; private boolean cacheOfAlphaIsInvalide =true; /** get method for property alpha */ public double getAlpha() { if(cacheOfAlphaIsInvalide) { cacheOfAlphaIsInvalide=false; cacheOfAlpha=computeAlpha(); } return cacheOfAlpha; } /** compute method for property alpha */ protected double computeAlpha() { return 5*7; }

  9. Redundancia • Hátrányok: • többletmunka • Inkonzisztencia veszélye • „Az igazi programozó, úgy programozik,mint a gép”(Vég Cs.) • Automatizálás lehetősége

  10. Forrásgenerálás • Automatikus forrásgenerálás: generikus szerkezetek segítségével Library Preprocessor Result Text Source

  11. Generikus szerkezetek • Makro eszköz • Preprocesszor • Definícók - definíciós könyvtárak • Hívás definition files original file result file Original text.. {Call 1} Original text.. {Call 2} ... Original text.. Modified text Original text.. New text ... Definition 1 Definition 2 ... +

  12. Generikus szerkezet alkalmazása • Hívás = tulajdonságlista • általános szintaktika • alapértelmezett tulajdonságok • UML-szerű megszorítások {property} {name=alpha} {type=int} {readable} {writeable} {property} {name=alpha1} {type=int} {!readable} {writeable} {property} {name=alpha} {type=double} {cached=5*7}

  13. Generálás /** The alpha (int) property */ private int alpha; /** get method for property alpha */ public int getAlpha() { return alpha; } /** set method for property alpha */ public void setAlpha(int alpha_) { alpha=alpha_; } {property} {name=alpha} {type=int} {readable} {writeable}

  14. Definíció (egyszerűsített) {property}: {<property-description} /**The %name% (%type%) property*/ {property} {!derived}:{<attribute}private %type% %name%; {property} {readable}: {<read-method} %visibility% %type% get_%name%() { return %name%; } {property} {writeable}: {<write-method}%visibility% void set_%name%(%type% %name%_) {%name%=%name%_; } {property} {derived}: {<read-method} %visibility% %type% get_%name%() {return compute_%name%();} {<compute-method} protected %type% compute_%name%() { return %derived%; } /** The alpha (int) property */ public int getAlpha() { return alpha; }

  15. Definíció {cached} {property} {cached}: {<cache}private %type% cacheOf_%name%; {<cacheFlag} private boolean cacheOf_%name%IsInvalide =true; {<read-method} %visibility% %type% get_%name%() { if(cacheOf_%name%IsInvalide) { cacheOf_%name%IsInvalide=false; cacheOf_%name%=compute_%name%(); } return cacheOf_%name%; }

  16. Forrásmódosítás • Hívások speciális megjegyzésként • A makroeszközmódosítja a programforrást Library Preprocessor IDE IDE ! Result Text Source

  17. Forrásmódosítás /// {property} {name=alpha} {type=double} {cached=5*7} /** The alpha (double) property */ private double cacheOfAlpha; private boolean cacheOfAlphaIsInvalide =true; /** get method for property alpha */ public double getAlpha() { if(cacheOfAlphaIsInvalide) { cacheOfAlphaIsInvalide=false; cacheOfAlpha=computeAlpha(); } return cacheOfAlpha; } /** compute method for property alpha */ protected double computeAlpha() { return 5*7; } Less tangled, smaller code Easier maintance More Reusable Common Code Localization

  18. Forrásmódosítás előnyei • A generált eredmény azonnal felhasználható • eredeti állomány a fejlesztőeszközben szerkeztés alatt áll • Az esetleges hibák könnyen megtalálhatóak és javíthatóak /// {property} {name=alpha} {type=doublw} {cached=5*7} /** The alpha (doublw) property */ private doublw cacheOfAlpha; ...

  19. Generikus szerkezetek előnyei II. • Testreszabás: • Korábbi definíciók felüldefiniálása lehetséges • felüldefiniálás közvetlenül akár az eredmény-szöveggel is {property} {readable}: {~read-method} %visibility% %type% get_%name%() { System.out.println(“get_%name%() method”); return %name%; }

  20. Elemző • Külön elemző definiálásának lehetősége • Rövidebb hivatkozások • Speciális körülményekhez igazítható • Alapértelmezett elemző : +alpha: int <  {property} {name=alpha} {type=int} {readable} {writeable}

  21. Elemző • További megszorítások (UML): +alpha: double {cached=5*7}  {property} {name=alpha} {type=double} {cached=5*7} • Specifikus elemző: {ui-elem} @ 23,41 JLabel(„Név”) {ui-elem} @ 78,41 JTextField() {from=person.getName()}

  22. Generikus szerkezetek • Generikus szerkezetek: • közvetlenül újrafelhasználható szaktudás • Alkalmazási területek: • Komponensek • Felhasználói felületek • Adatbázis-illesztés

  23. Irodalom • C. Szyperski.Component Software. Beyond Object-oriented programming.Addison-Wesley.(elméleti áttekintés, alapelvek, technológiák áttekintése) • Vég Cs. Alkalmazásfejlesztés a Unified Modeling Language szabványos jelöléseivel.Logos 2000., 1999. máj.(UML ismertetése, OO szemlélet, UML komponens-elvű kiterjesztése, RDD alkalmazásfejlesztési módszer) <www.logos2000.hu>

More Related