• Tidak ada hasil yang ditemukan

BlTl.DING SOMF. DESIGN PATTERNS IN C#

N/A
N/A
Protected

Academic year: 2024

Membagikan "BlTl.DING SOMF. DESIGN PATTERNS IN C#"

Copied!
10
0
0

Teks penuh

(1)

Niiuven Manh Dire Tap chi KHO \ HOC & CO\G NGHH 9()((I2): T" - 86

BlTl.DING SOMF. DESIGN PATTERNS IN C#

Nguyen Manh Due College nl Education T\ I Sl MM \\<\

In software engineering, design is a total solution for common problems in softwai'c design.

Profound idea of the design is good saving solutions-oriented design and object re-use them to solve similar problems. Neu object oriented language C=. Mici'osoft's inllucnccmany of the languages Java and C+-. But there are still many neu and inteicsting featureis introduced to simplify the design of object-oriented. In this article uc uill consider building a nuniber oldcsigns that Gamma has proposed language with C=-.The purpose oflhe work here is to have an insight than some designs can be implemented in C ". to learn the neu features of the language in practice and make it easier lor designers object-oriented soltuare.

Key words: Design I'citfei-fis. Singleton. l'rox\. Ihstrucl f adnr-t Strutegy. I'.Ml INIRODUC'IKiN

Object oriented programming has been the dominating style in sollware development for quite a l'cv\ years, Tke inltiilivc way in wkick objecl oriented languages allow us lo divide our code into objeels and classes is wkal makes tills style of programming iillractivc

\notlier aim of obiecl orienled program design IS to make code more reusable.

However practical lias skown ikal designing reusable object oriented sollware is noi always llial easy, ,\ good software design should, not only solve existing problems, bui also concern rtiUire problems. It skould make the |iiogram llexiblc. easy lo niauilain and lo update Design pallerns kelp us addicss these issues Ike idea is quite simple, wc save document and design sokilions llial kavc been Used and worked lor reoccurring problems, in order to use tkem again in similar situations.

Iiisoliwarc engineering, a design pattern is a loi.il solution lor common problems in

•.oftware ilesign. A design pattern is not a pcrl'ccl design lor can be coin cried Jircclly mio code, il i's onlv :i framework describing how 10 solve a problem tkat can be leiised in many dil'l'cient siiualioiis. The objccl oriented design patterns typically show rekitionskips and interactions between classes or objects.

w itkout specify ing ikc class or object ol cack specific application.

The design can help speed up ihe process of sofrware dcvelopmenl by providing development pallerns lia\e been authenlicaled and \erillcd. ll pro\ ides general sokilions.

documented in a roinial tkai is not attacked to a particukir problem, Ike model allows de\clopcrs lo commiiniciitc witk cack other Using the iiiime easy to understand, is widely iiscd to set for the inlcraclion of software | 1 |

I he aim of ikis work is lo lake a closer look al kow some of tke kiiovMi design patterns can be iiiiplcnienled in Cit. and lo iinesligale whclkcr ike new realures of the language in fact do make il easier to design object onciucd soflwaie,

MJci the inlrodiiclion. section 2 will i'c\ lew some of ike designs represent tke Gamma and colleagues have pioposcil | 1 |. we pi'oposc how to design and biiiki ihcsc templates in C - and apply tkem in some real-v\orld problems; scclion 3 discusses some issues of inlercst. kinallv section Iwill include a number of conclusions and rtiturc work.

Dl SIGN SOMl. P,\l n.KNS IN ( ;;

Ihc designs are iinportanl building blocks for design and modeling applications on all pkitroriiis. Ihe design kelps us lo uiidcrst.iiid. discuss and re-usc of appliciitioiis on aparticular pkitloiiii. In | I | Gamma and

(2)

Niiuven Manh Due Tap chi K l l O \ HOC A; CONG NCdU 90(02): - - - 86 colleagues proposed 23 designs, tliev are

classified into 3 types are: creational patterns, structural patterns and bekavioral patterns. Here we w i l l review a represent- tative sample for eack tvpe.

C r e a t i o n a l Patterns

Creational pattern as the name implies are concerned with tke creation o f object. Tke patterns kelp you build i part o f an application that hides how an object is cieated and composed from the i-cpre.sentiition o f the object. The only information known o f the object is its interface. Creational patterns can be divided in class ei'cational patterns and object creational patterns The difference lies 111 that the class creational pallerns use inheritance to iiistantiale a class, while object creational patterns delegate tke iiistantiation to anotker objecl.

Here v\c w i l l look al the Singleton and

\bstract I'iictory patterns represent creational patterns

Singleton Puttern

Singleton design pattern is designed to ensure Ikal a class can only create a unique skow and il prov ides access points in a uniform global.

In fact, tkere are many situations where we want a class has only a single skow during application execution. Singleton design pattern kas been born to meel tke problems o f tkis type.

Ihe siructiiic o f tke Singleton pallern is represented bv tke 1 \ I I diagram sliov\n in I'igiirc I | l | .

Singleton

Singleton OperationQ GctSinglelonDataO static uniquelnstance singletonData

Return uniquelnstance

l-'igurc 1: Sfr'.'i tttre ol the Singlelon putlern

I n s t a l l a t i o n : Singleton design palteni can he installed in the C= language as fallows, class Singleton

Field

private static Singleton instance:

Constructor

protected Singleton() [ i Mctkod

public static Singlelon lnstance()

I I

if (instance == null)

instance - new Singlcton().

return instance:

.Apply the .Singleton p a t t e r n :

P r o b l e m 1: Suppose the need lo build a I ind dialog box and scarck for a text editor. Nolc thilt in all cases to ensure that only up lo a Find dialog box appears kir convenience lo usei's and for the management o f the sy stem 11 ].

The most reasonable solution for tke above case is designed for that class can express itseontrol. SpecilJcally. ike class w i l l always ensure thiit no otker skow can be ci'ealcd f i o i n it. Normally wken an object lo be cieated from the class must be crciitcd through function (constructor) o f that class.

Therefore, to prevent the user create objects freely, v v c w i l l prevent the creation function can be called, by turning it into a private domain (or protected) in the class. Then provide a sialic m c t k o d . lo create new ob|ccls in a c o n t m l l c d . icckeck i f tke objccl u i l l not create new ob|ccls. otkerwisc it returns tke object already exist. Tkis solution will ensure "only one instance o f the class onlv.

Tke clients to access instance o f class through the constructor mentioned above Thus, the Find dialog box can be installed as follows public class Find

protected static Find instance null: field protected Find() { ; constructor public static Find Singleton!) method

7S

(3)

Nguven Manh Dire Tap chi KHOA HOC & CONG NGHE 90(02): 77 -

if (instance =-- null) instance ^ neu Find():

return instance;

} I

11 a user creates ai. instance of the class with tke command: Find tind

It will kave compile errors, so constructor of tke class is located in soutkern private (protected) Instance of Ike class can only be made by:

Find find I'ind.SingletonO:

Therefore, we c m completely control the instance of the class created in the nietkod Singleton(). ensuring tkat only one tke an object.

Prohlcm 2: Anotker application is a class that can be designed lor its inrormation accessed globallv by all otker objects in the program, l o r cxaniplc. sometimes we need a singleglobal object store inl'ormalion comiecled lo tke database or infonnation Ikrougk conipiitei" networks connected to otker objeels eaii be accessed as needed lo produce tills singleohjecl | I |, Spccincally. we

need to store information aboiil a database inekide: ServcrNanie. DatabaseName.

I serName and Password. Need to iiccess ike inl'omiation at any lime and anywhere in the pi'ognim V\ e can use the Singleton pattern soke this problem as follows:

public class Datalnl'o priv.ile string ScrvcrNamc.

priv.ilc siring DalabaseNiimc.

privalc string LscrName;

pru.ue string Password:

prolectcd sialic Dalalnfo instance null:

protected Datalnfo(siriiig servcrname.

string datab.isename.

siring username.

siring passu Old) sei'v Cl Name sei"\ ernanie:

Dai.ibaseN'amc d.il.ibaseiianic:

I scrNamc username;

Passuoid password;

publie string gciScrvciNameO

return ServerNanie:

public static Datalnfo SinglelonO if (instance =' null)

instance new Datalnfo("DHTN"

"dala201 1" "Le ,\n" "an-dkln"):

return instance;

class Program

•f

si.iiic void Main(string[] args)

Datalnfo dalalnfo ' Datalnfo,SingletonO Console,\\ ritcLiiieC'ServerNammc "

dalalnfo,aetServcrName()):

.Ihstriict Factory Pattern

,\bstraet Factory is a design pattern provides lo tke client program an interface , wliich is a family or a scl ofobjects of different classes have the same interface with eack other, which Is not directly work with each subclass particular.

.Abstract Factory design pattern to pack a group ol tke class acts as a "production"

(factory) in the application, tkis is the class used to create objects. Ike production of ihis the class liiivc a common programming iiilcrracc tkat is inkeriled Irom a parent class

pure virtual called class "virtual factorv class"

Siiuclure of Ikc Abstract Fiiclory pattern is represented by tke I Ml, diagram in Figure 2 11], Olwkich:

ConcrcteFaetory: real-time mclkods in ,\bstiactFaclory to eieale tkespecilic objccl. The system has many objects.

tke groups gcnciiitcd bv tke t oncrctekact-orv similar role.

.\hstractFactory : is abstract, il specilles tke interlace for manipulating create

"products" virtual (.MislractProduct),

Product' \ s tke reality of object generated from the concretcl'aclorv class

(4)

Niuven Manh Dire Tap chi KHOA HOC & CONG NGHE 90(02). " - 8 6 At5rjc'-Fasfj.-y - • -

^hi-i.-r."',',.s3-v-r4

• - Pro0uctA2 P r o d u c t A l - • 1

^;=;;;;.;;:^::^:; '

Concrelefactorva C^eattPiuduclA,;!

"-^.I'pPrnrJur'B: Ae.i-j.'ifc<i,c:s U -

PrcxluclBS , PtcxJuclBI - •

Figure 2: .Structure ol the .-tbslruci Fuclorr puticrn

AbslraelProducl.

• C l i e n t : K a p r o g r a m to c i e a l c objects in ike s y s t e m . i t iiscs AbslractFactory and AbslraelProducl

B u i l d i n g A b s t r a c t F a c t o n P a t t e r n in C # : Imagine you are d e s i g n i n g s o l i w a r c to build an electric motor. First y o u must d e t e r m i n e ike \bctiMcFaclory and \ b s i r a c l P r o d u c l classes W e called t k e m D o n g C o F a c t o r y and D o n g C o . these c l a s s e s are installed in Cf- as follows

•ihsiMcl cl.iss llongCol.iciorv

public .ihsiraci DongCo gelDongCot 1:

.ihsiiMci cl.iss llongCo i

public abstraci string type i gel. ;

Now we d e l l n e a product class DongC ol 50lll'iodiici for DongCo class, ConcrcteFaetory class for D o n g l o r a c t o r v

el.iss l l o n g i o l .^iioProduci DongCo suing type ^ "DCE-5n(i"

public override string type gel ! return type: I

cl.iss ^oiieiclcDoncl ol.i^lorv I Doniilol acloiv

public override DongCo gelDongCo() {

return new Doni;CoF500Pi'odiicl():

W c now k a v e a factory and the product, ready for the i m p l e m e n t a t i o n o f tlieclasses and build tke e n g i n e s But first w e need a client and a M a m class. H e r e , tke client class is icslllrivcr.

class TeslDriver

i public void-ModeKDongCoFactory laclorv)

f

DongC o dc factorv ,gell)oiig(. o(), Console \\ ritekinei"Model ; 0 | " . dc.tvpe).

class Program

static void M.iinisinngj | args) DongCoFactory lacloiy I

new concreteDongl ol aclory 1().

new TestDriveri i Modcldactorv I);

Coiisole.Readl mel 1.

N o w . 10 add a n o t h e r factory c l a s s and otker IV pes o f DongC o can be m a d e as follows:

class DongCoE'oiiProdiicr DongCo I string type "DCL-700";

80

(5)

Nguven Manh Dire Tap chi KHOA HOC & CONG NGHE 90(02): 77 - 86 public override string type

gel { return type; }

class concretcDongCoFaclory2 : DongCoFactory

t

public override DongCo gelDongCoO return neu DongC ol:700Producl():

Now wc add code to the M;iin fiiiictioii as follows, and tken implement programs to prcseiitperformanee results, and note lliat the clieiil class is ikal teslDriver not remain iinaltcrcd.

class Program

si.iiic void MaiiKsiringI | .irgs) DongCoFactory factory 1

new concrelcDongCol aclorv l().

new 1 csiDrivci'O Model(l'acloiy 1):

DongColactoiy factory2

new coiici'elel)oiigCoFactory2():

neu resiDrivcrO \lodel(laclorv2):

Ikc above example skovvs tkat kow to add I I'aclory and a new product into tke sysleni.

Structural Patterns

Structui'al patterns suggest ways to pul togclker cxisling objeels into complex siriicliircs. in order lo ackieve new

funclionality. Class structural patterns use inkeritancc to compose interlaces and implementation, wkereas in object structural patterns an object can reside inside anotker object. In this section, vvcwill rev lew n representative sample for tkis model, which is the proxy pattern.

Proxy Pattern:

Pro.xy patleni is used when the need to replace, or more accurately repicsenl a complex objecl with a simple olijccl. Hike initialization of an object thai consuming too many resources or time, the Proxy pattern is a good solution, it allows only il'clearly needed

I newinitiali/ed object Proxy now can be applied any where where you need lo have an ob|cclrelei"ciice to a more llexiblc. moic sophisticated llian using a simple poinler The slructure of the Proxy palteni is presented in Figure 3 | I |. Of which:

• Subject: A pure v irtual objecl class or interlace, this class can be inhcriled and implemented by Proxy and other objects.

RcalSubjcet: Inherit from ihe Subject, its full implementalion or expansion funclions defined in ihe Subject.

Proxy: Inkerils from Subject, it is responsible lor transfer limelion calls (requests) from tke Subject to RealSubjccl wkencvcr ncccssarv.

Client

RealSuhjcct

-•I Subicct

Hrr, .:••.•,'!

. - i l - : i , l i . T i Proxy

L

Hegj'.-sir '-- :ii-;rh', , I ..Pr-

Fiuure 3: Siriiclure ol the Pr,i\\ pattern

(6)

N'iuven Manh Due Tap chi KHOA HOC & CONG NGHE 90(02): 77 - 86 Building Proxxy pattern in C#:

Fhe following example will illustrate the installation of Proxy pattern in CU. Suppose weneed to build a serv ice processor in a computing system, we can build this service form Proxy pattern as follows:

First define an delegate Calculate as follows:

public delegate int Calculate(int a. int b);

Fken tkere is an interlace iMaili role for Subject:

public interface IMalh

int A D D ( i n t \ . int y ) ; int S U B ( i n t \ . int v ) ;

And next is a M.uh class is inkeriled from tke

\l,iishiilB.vRcR)bieei class IMaih and tke system acts as KealSub.icci;

el.iss Mmh. \l,irshalBvRcH)hieei. IMalh publk im MIDlinl \. im y) | relurn \ ^v. 1 puhlie ml sl H( ini \. im v) | rolurn \ - y; ] inkcritcd from class iM.nh:

cl.issMiiihl'rovv; IM.iih

\liilh math neu Maihi):

public \liilhPro\.v()

t oiiMilc.W rilcl.inel t aleuliiior eonslrucloi"):

1 ao the hien cua Math Irong mm

AppDoni.iiii kh.ic AppDoniain ad ^

S\sicrn Vppl)oni.iin C rcilcDoniilinCMallirioinain"

null, null).

public nil V l l D l i m \ . ml \ I

relurn iiialh ADDlv. v l.

public im sl Bdni v. ini v i return nialh.sl Hl\. v i:

Fills class will change tke calculations required lo kandle RealSubjecl class when needed

Next wc add the Client class, tkis class lias two metkods: \ul.v used delegate packaging metkods calculation processing serv ices and Displa.v to create Proxy objects and call kandling requirements necessary calculations:

public class Client int \ = 12. V = '.

void .\ul.v(Calculate eal. im v 1. ml v2)

Console Wriiei" nXu 1} voi:|()l. | I I '.v l.v2):

Console,\\ rilcl.inel "Kel qua = [()!".e.il(\ I. \2)):

public void DisplavO

MathProsv mp = new M;iihPro\v():

Caleuliile pi =- neu Calculatc(mp.ADU):

Xiilv(pi. \. s):

pi ' mp.sl'B:

Xulv(pl. ,. .V):

In ilkislration of tkis Proxy applicalion pattern, wc have used linatk interl'acc to determine tkcscrv ice requiiemenls. delegate

lecliniciaiis to perform the calculations required and ihcprocess of creating objects in CU language instead of kav ing lo use oi'dinaiy pointers as in C M . lo .save resources and case of kandling.

Behavioural Patterns

Bekav ioral patterns focused on problem solving algorithm and the division ol responsibilities between objects. Behavior patterns are most concerned lo the transmission of communications between objects, Bchav ioral patterns not only describes the objecl model of the model but also describes Ike exchange of information between them; charaeleri/c complex control fiovv. enabling lis to locus more on how to build links between objects instead of the control fiovv. Here wc consider the strategy pattern represent for bekav ioral patterns.

Strategy pattern:

Tke Strategy pattern defines A family ol algorithms. encapsukitcs the iclatcti algorithms and makes them inlerckangeablc.

This allows the selection of algorithm lo vary

s:

(7)

Nguyen Manh Dire Tap chi KHOA HOC & CONG NGHE 90(02): 77- indepcndently from clients that use it and

allows it to vary over time [ 4 ] .

i h e structure o f l h e Strategy pattern as shown in Figure 4 111. in w h i c h :

Strategy: D e f i n i n g the interface for all classes present algorithm. D u r i n g the initialization process may object to add data from the Context.

ConcretcStratcjiy: Is the implementation o f the Strategy interface to present a specific algoritkm.

Contevt: A l compile time, only to use Ike object Strategy model vvkeii determining lliciilgoritkm for the problem to be treated; ,Al the time o f execution given a specific object ol algorithm replacement for object Slralcgv, Building Strategy pattern in C'#:

Ihe eonstruclion behind the Slralegy pattern is to encapsulate tke number o f strategies in a single module and provide an uncomplicated interface to a l l o w Ike clicnls lo choose between these strategies I f you have sevei'al diffci'ciil bekav ioiirs ikal you want an object to perform, il is muck simpler to keep track o f tkem i f each behaviour is a separate class, instead o f the most common approach o f pulling them in one nielkod. Fliis is illustrated in figure 1 | 1] By doing ikis you can easily add. remove, or cliange tke dilferenl bekav iours. since eack one: is its o w n class.

F.acli suck bekavioiir or algoritkm eneapsulaled into its o w n class is called a Strategy. I k e siratcgics do not need to be members o f l h e same class hierarchy but they do kave to implement tke same interface [2], The new language support for interfaces in C# conies in handy when implcmentmg tke Slralcgv pallern, C + + programmers typically ci'eale interfaces by defining abstract classes witk puie virtual metkods. In C#. all interface

members are public, and classes adkcring to an interface must implement all methods in the interface.

The f o l l o w i n g code demonstrates tke Strategy pattern, which encapsulates functionality in the form o f an object. This basic example is based on the structure in figure 4.

First we create an Slralegy interface with its method are \!goriihnilnterl'iice(|:

inlerliiic Slralegv

void .Mgorilhmlnterraeel):

Next is subclass o f concieteSlrategy inherits tke Strategy interface, w k i c k corresponds to thealgoritkm o f eack case w i l l be selected st ratcgy:

el.iss ConcreieStraiegv.V Slralcgv public void MgorithmlmerliiceO

Console \\'rilel,ine(this loSinngO):

el.iss C"oncretesirategvB Siralegv puWie void Vlgonlhmliileilaeel 1

Console Wriiel.iiiedhis loSlring(l).

cliiss ConcieieSirategyC : Siratecv public void .MgorithmlnterraceO

Console-Writel inedhis, I oSlringO):

- ^ Strategy

ConcroteSlr.itegvA A ii,, ai c-ii'iieri,-

CoficreleStralegv B ConciGleSlralGgyC

Figure 4: Strn,. lure o/ the .Strategy pattern

(8)

Nmiven Manh Due Tap chi KHOA HOC ..^ CONG NGHL 90(02) -86 Next is the Context class will provide specific

algoritkm obiects as required:

class C onieM

private Slralcgv siralegv;

publiL ConleMisir.iiegv siralegv) ihis siralegv = str.ilegv:

public void Conlexllnlerr.ieel) sir.lieu) Alcorilhmliilerl'aeel).

Finally, tke class tkat contains Ike Mam function to execute tke progiiim:

cliiss I'logram

simie void \l,iimsirmg[l args) C oilIeM e \ - ne\\ C oiile\l(

neu CDnereieSiraiegv ,\()).

e,\,C"onle\lliiierl.i».e():

( onieM eii - neu C"onle\t(

neu I oiKreieSii,iieg\B(ll, cB I omevllnlerlaeei).

I'oillevl cC neu (. onlevll

neu ( onereiesiralegvl (ll.

^i I oiile\llnler!.ii.ei):

DISCI SSION

,\ design pattern is a description of a set of interacting classes tkat provide a framework foi' 1 solulipn 10 a generalized problem in a spccillc coiucxt or ciiv ironmenl. In otker words, a pallern suggests a solution to a particular problem or issue in obieet-oricnted software dcvelopmenl

in today s software development, applications and systems are complex. Tkese pi'oducts require a great deal of fiexibilitv in design and ai'ekileclure to accommodate the ever- changing needs of clients and users during the product development and also after tke product kas been released Design patterns assist in laying tke loundation for a fiexible S4

architecture, which is tke cliaiacteristic of every good obiecl-orienlcd design |.s. 6|.

C - together with .NIM brings about many benefits, including tke easy-to-use object model, tke garbage collection meckanisni lor automatically cleaning up resources, and far improved libraries covering areas raiigini;

from \\ indows GL I support lo dala access and generating web pages. Fke .Nil' framework insures tkat enougk informiUion is included in tke compiled library files (the assemblies) and tkat your classes can be inkeriled from and used by oilier Nl I -avvaie code witkout requiring access lo your souice files 13. 1|,

I he recoi'd in fact slunvs thai poiiilcis is one of the largest sources causes errors when developing sollware. ike eoncepl of pointers ill C and C ' • does noi exist in C #. Ilovvevci', il can overcome tins problem in C/i using otker mcckanisms suck as: set the refeiencc variable with the parameters of the iiiclhod.

or by ihe constriiclor the object classes |4|,,, .\ii interface is basically a eoiuracl between a class and a client tkat guaranties that Ike class implements the methods specified in the iiuerfiiee In otker words, interfaces contain the public signature of methods, events and pi'opei'tics but it Is up to tke class, which is said to tinplcntetil the inlerface. lo provide the implementation of these mcthotls. The implementing class inhcrils li'om an interface in the same way as from a base class An instance of this class can then be casled into the inlerface and access its methods In this way interfaces can be used lo reach Ike same objectives as with multiple inkerilancc |5. 7].

,As Liberty | 2 | states, in tke programming language C-'^. delegates are first-ckiss objeels.

fully supported by the language. Using a dclegiite allows tke programmer to encapsulate a reference to a mctkod inside a delegiilc object i o u can encapsulate anv malcking mctkod in tkat delegalc wilkoiil kav ing to know al compile time wkich nictkod tkat will be invoked. ,\ delegate in C*' is similar to a function poinler in C or C+*

(9)

Neuvcn Manh Dire Tap chi KHO,\ HOC & CONG NGHE 90(02): 7 7 - 8 6 Bui unlike function pointers, delegates are

object-oriented. type-safe and secure managed ob|ects.

One o f the primary goals o f i'U is safelv;

many o f tke problems tkat programmers can ciiiisc in C and C* arc avoided in Cii Generally tke absliaetion level o f programming is kiglier in C# compared lo ( Introducing C# in design patterns provides the programmer w i t h a modei'n object-oriented programming language ollcring syntactic eonstnicts and semantic support for concepts tkat map directly to notions in object-oriented ilesign,

Ike designs show tkat you always have a pi'ogram w i t h an interlace does not cnfoi'ce it, Iken. in all inkcritcd classes, you w i l l be more llexiblc implementation o f Ike nielkod IS mosl suilable l o y o u r purpose. Since C*i supports interface, this feature is useful vvlieii implemenliiig patterns as Adapler. Slralegy.

.Abstract Factorv ,,, I kc Iccknical delegate an dolkei" events also mulck Ike lealuics o f l h e design and for the design of llic patterns becomes casiei",

C O N C I . l SION

In soflwiire engineering, design is a total solution for common problems in software design. Profound idea o f the design is good sav ing solutions oiiented ilesign and objecl ic-iisc them lo solve similar problems

New obiecl-orienlcd language CH is Microsoli's influencemany ol'tlic languages Java and C ' i , Hut ikere arc still niaiiv new and exciting fealures are inlioduced lo simplify object-oriemed design. In this article we w i l l consider building designs w k i c k some kave proposed Giinima by CU l.iiigii.igc, namely tke Singleton patleni.

Misiractl .leioiy. Proxy and Slralegy 4 licsc models arc built based on some new features o f c suck as crciiting a single object using the static method, the use o f abstr.icl classes to define Ike interface lor manipulating create "prodiiets'' virtual:

teckniqucs aulhorized to perform the

required processing requirements and meckanism for creating objects in C K instead o f using pointers to n o n i i a l C * ' and use tkis technique class inkeritancc and interfaces instead o f multiple inkeritancc in C+ r to implement multi-processing forms...

Object oriented language C •'. Mieiosoli's infiucncemany o f l h e languages Java and C-^^. But thci'c ai'C still many new and inlercsiing fealuieis introduced lo simplify the design o f object-oriented. In tkis article we w i l l consider building a number o f designs tkat Cjamniii kiis proposed language witk C " I k e purpose o l ' i k c work kere is to kavc an insigkl ikaii some designs can be implemeiiled in C •':. lo learn ikc new features of the kingtiagc in practice and make it easier for ilesigners object-orienled sollware.

In tke futiii'c v v c w i l l look at otkci patterns and build on Ike languages C - or Java, Research

on the lelliic designs \|)plic:ilioii loniis and combine them lo solve tke problem in piaclice,

R F F L R l N C 1 S

111. Gamma 1... et. al. Elemenls of Reitsuhle Ohiecl-Oricnled Softwure. ,\ildisoii-\\ esley , The PDF conversion was made in icbruarv 2003

|2], l.ibci'tv J.. Progrumming Cff. 2nd Edition.

O'Rcillv. ISBN 0-.s9(>-0ir,(l9-9. 2002

|3| XPsDN. C'f l.ungtiuge specilicution I"

Utribuies. Microsoft Corporation 200 1,

| 1 | Malhias Hartoll, Nori \hari. Oliver C Moldez.

Design pullerns in ('". Malardalcn University

\ asieras, Sweden 201)1,

| 5 1 . S h c r i f \ l i acoub. 11 H, Ammar. Puttern- Oriciifed Analysts und Design Composing Puff^rns lo Design Softwure Srslems. ,\ddison Wcslev 2003.

[6|. Nguven M.iiih Due (2011). "Some calcukitions and lellnemenls with the components" Journal of Science and

I echnology. Universiiv of J hai Nguven.

volume "8. No. 02. p. 97-104

["] Pham Huu Khang. "I ran fien Dung. C" 2005 Objecl Oriented Programming. Publishing House of-social Labour. 2008.

(10)

Nguven M.i:-h Due Tap chi KHOA HOC .X CONCj NGHE 9 0 ( 0 2 ) : — - 8 6

T O M T A T

\ Vi D l N G M O T S O M . \ L T H I E T K E T R O N G C-=

Nguy i'n Manh Oiic Tnrmtg Dgi luK-S:. pham Dai hoc Thdi \gu\en

Trong cdng nghe phan mem. mau thiet ke la n o t giai phap tdng the cho cac van de chung trong thiet ke- phan 'neiii, i ' tuong sau xa cua cac mau thiet ke la de tie; kiem tdt cac giai phap thiet ke hucmg doi tugng vav ,cc tiii su dung chung .;e giai quvet cac van dc iiioiig tu. Ngon n g i hmnig ddi tuong mdi C= sua hang Microsoft eo anh iiLioiig nhieu tir cac ngdn ngir Java vii C - -. tuv nhien van con nhieu tinh nang mdi va thu vi duoe gioi ihieu de don giiin hoa thiet kc hudng doi luong.

Irong bai bao nav chung tdi sc xem \ei \av diniu mdt sd niiiu thiet ke ma Gamma dii de xuiit himg ngon ngir C=. Tu Jo co 'iioi cai nhin sau s.'ic hem mot so miiu thiet s,; co the thuc hien trong C=.

um hieu sjs tinh nang moi cua ngdn ngir uong thuc te va lam cho de Jang hem trong thiei ke phan mem huong Joi tugng.

Tir khoa: Cue mdu ihiei ke. mdu S:ngief"n mdu Pro.xy. mdu Ihsirucf Fjciory. mdu Sirjfcgy ngim ngir md hinh lu'hi ihdng nhdi.

" ' ' - _ - • cm... nm.nutn a yanoo com Sd

Referensi

Dokumen terkait

As a conclusion, to determining if the marketing strategy can enhance the customer’s buying behavior on purchasing a house, developer have to know the knowledge on customers

Modules thus provide a perfect way to allow objects of different classes to play a common role using a single set of code.. When an object includes a module, the methods defined

A method for determining the parameters of such networks, given expression level time series data, is introduced and evaluated using artificial data.. The method is also applied to

an object, and the tendency to act. These four components will form a complete attitude. Knowledge plays an important role in determining attitudes [21]. According

Like an object reference, a dynamic reference can point to an object of any type (except pointer types):. dynamic x

DISCUSSION 3.1 Innovation Strategy as a Driver of SME Performance Advancement technique will be a way driver to the execution for little and medium ventures SMES toward applying

This analysis was chosen to be the basis for determining the strategy used to survive in the world of e-commerce that can increase sales from the home industry [31]–[33].. 5 Develop a

Motivation • Find a steady-state corresponding to given values of inputs steady-state solution • Find how state variables change over time when inputs change from a previous steady