ª«¥ó¾É¦Vµ{¦¡³]p¡]Object Oriented Programming¡A²ºÙ OOP¡^¬O¥Ø«e³nÅé³]pªº¼é¬y¡A¤@¯ë°ª¶¥µ{¦¡»y¨¥³£¤ä´© OOP ªº·§©À¡A¨Ò¦p C++¡BJavaScript¡BC#¡BJava µ¥µ¥¡AMATLAB¤]¤£¨Ò¥~¡A¦]¦¹¥»³¹±N»¡©ú MATLAB ¦b OOP ·§©À¤Uªº¼¶¼g¤è¦¡¡A¥H«K²¤Æ³nÅ骺©â¶H·§©À¡B´£°ªµ{¦¡½Xªº¥iŪ©Ê»P«½Æ¨Ï¥Î©Ê¡A¨ÃÅý³nÅ骺ºÞ²z§ó¥[²¼ä³z©ú¡C
º¥ý¡A§ÚÌn¯à°÷«Ø¥ß¤@ÓÃþ§O¡]Class¡^¡A¨Ã¸g¥Ñ¦¹Ãþ§O«Øºc¥X¹ê»Úªºª«¥ó¡]Object¡^¡A¦p¦¹¤~¯à¶i¦Ó¨Ï¥Îª«¥óªº¦UºØ¤èªk¨Ó¹F¦¨À³¥Îµ{¦¡ªº³Ì«á¥Øªº¡CÃþ§O¬O¤@ÓµêÀÀªº·§©À¡A¨Ò¦p¡u¤H¡v¥i¥H¬Ý¦¨¬O¤@ÓÃþ§O¡A¥]§t¦UºØ©Ê½èªº©w¸q¡]¨Ò¦p¦W¦r¡B©Ê§O¡B¨°ª¡BÅ髵¥¡^¡A¦ý¬Oª«¥ó«h¬O¹ê»Ú¥ÑÃþ§O²£¥Íªº¹êÅé¡A¨Ò¦p¡u¤Õ¤l¡v©Î¬O¡uª÷«°ªZ¡v´N¬O¥Ñ¡u¤H¡v©Ò²£¥Íªº¹êÅé¡A¦¹¹êÅé´N·|¦³½T¤Áªº¦W¦r¡B©Ê§O¡B¨°ª¡BÅ髵¥©Ê½è¡C
¥H¤U§Ú̱N¥H¥ý¦h¶µ¦¡¬°½d¨Ò¡A¨Ó»¡©ú MATLAB ¦p¦ó¹ê§@ OOP ªº°ò¥»·§©À¡CMATLAB «Ø¥ßÃþ§Oªº¤è¦¡¬Oª½±µ²£¥Í¤@Ó¥H¡u@¡v¬°¶}ÀYªº¸ê®Æ§¨¡A©Ò¦³»P¦¹Ãþ§O¬ÛÃöªº¨ç¦¡³£©ñ¦b¦¹¸ê®Æ§¨¤§¤U¡A¨Ò¦p¡A¦b¥»³¹ªº½d¨Òµ{¦¡¥Ø¿ý¤¤¡A§A¥i¥Hµoı¦³¤@ӥؿýªº¦WºÙ¬O @polynom¡A³o´N¬O¹ïÀ³¨ì¦h¶µ¦¡Ãþ§Oªº¥Ø¿ý¡A©Ò¦³¬ÛÃöªº¨ç¦¡¡]¤]´N¬Oª«¥óªº¤èªk¡^¤]³£©ñ¦b³oӥؿý¤U¡C
±µµÛ§ÚÌn©w¸q«Øºc¨ç¦¡¡]Constructor¡^¥H«K²£¥Í¦h¶µ¦¡ª«¥ó¡A¦¹«Øºc¨ç¦¡ªº¦WºÙ¥²¶·©MÃþ§Oªº¥Ø¿ý¦WºÙ¤@¼Ë¡]¦ý¤£¥]§t ¡§@¡¨¡^¡A¥H¦h¶µ¦¡ª«¥ó¦Ó¨¥¡A«Øºc¨ç¦¡ªº¦WºÙ´N¬O polynom.m¡A¨ä¤º®e¦p¤U¡G
±q¤Wzµ{¦¡½X¥i¥H¬Ý¥X¡G
¦pªG¿é¤J¬O¤@Ó¦V¶q¡A³o´N¬O¦h¶µ¦¡ªº«Y¼Æ¡]°¾±Æ¦C¡^¡A§Ú̱N¦¹«Y¼Æ³]©wµ¹ poly.c¡A³Ì«á¨Ï¥Î class ¨ç¦¡±N poly Åܼƥ[«ù¦¨ polynom ª«¥ó¡C
¦pªG¿é¤J vec ¤w¸g¬O¤@Ó polynom ª«¥ó¡A«hª½±µ¿é¥X¦¹ª«¥ó¡C¡]isa(vec, ¡¥polynom¡¦) ¥Î¨ÓÀˬd vec ¬O§_¬O¤@Ó polynom ª«¥ó¡C¡^
¥Ñ¤Wzµ{¦¡½X¤]¥i¥H¬Ý¥X¡Apoly ì¨Ó¬O¤@Óµ²ºcÅܼơA¨ã¦³¤@ÓÄæ¦ì c ¨ÓÀx¦s¦h¶µ¦¡ªº«Y¼Æ¡A¦ý¬O¤@¥¹¸g¥Ñ poly = class(poly, ¡¥polynom¡¦) ¨Ó±N¤§¥[«ù¦¨¬°ª«¥ó¤§«á¡A§Ú̦b¥~³¡¨ÃµLªk¸g¥Ñ poly ª«¥ó¨Ó¨ú±o c Äæ¦ìÈ¡A¦Ó¥²¶·©w¸q¨ä¥L¤èªk¨Ó¨ú±o¸ê®Æ¡]¸Ô¨£«áz¡^¡A³o¤]¬O OOP ªº°ò¥»ºë¯«¡G©Ò¦³ª«¥óªº©Ê½è¬OµLªk¥ô·N¶}©ñµ¹¥~¬ÉÀô¹Ò¡A¦Ó¥²¶·¸g¥Ñ»P¦¹ª«¥ó¬ÛÃöªº¯S©w¨ç¦¡¨Ó¨ú±o¡C
¦³¤F¦¹«Øºc¨ç¦¡¡A§ÚÌ´N¥i¥H«Øºc¤@Ó¦h¶µ¦¡ª«¥ó¡A¦ý¬°¤F¤ñ¸û¯à°÷Àu¶®¦a®i¥Ü¦¹ª«¥óªº¤º®e¡A§ÚÌ¥i¥H¼g¤@ÓÅã¥Ü¨ç¦¡ display.m ¨ÓÅã¥Ü¦¹¦h¶µ¦¡¡A¦¹Åã¥Ü¨ç¦¡ªº¦WºÙ¥²¶·©T©w¬° display.m¡A¥B¥²¶·¦ì©ó @polynom ¥Ø¿ý¤U¡A¤@¥¹ MATLAB »ÝnÅã¥Ü¦¹¦h¶µ¦¡ª«¥ó¡A§Y·|¦Û°Ê©I¥s¦¹¨ç¦¡¡A¨ä¤º®e¦p¤U¡G
¤Wz¨ç¦¡©I¥s¤F¥t¤@Ө禡 polyAsString.m¡A¨ä¥\¯à¬O±N¦h¶µ¦¡Âର¦r¦ê§Î¦¡¡A«K©óÆ[¬Ý¡Aµ{¦¡½X¦p¤U¡G
¤@¥¹¦³¤F«Øºc¨ç¦¡ polynom.m ©MÅã¥Ü¨ç¦¡ display.m «á¡A§ÚÌ´N¥i¥Hª½±µ²£¥Í¤@Ó¦h¶µ¦¡ª«¥ó¨ÃÅã¥Ü¦¹ª«¥ó¡A¦p¤U¡G
¦b MATLAB ©R¥Oµøµ¡©Ò²£¥Íªº¦r¦ê¡A§Y¬O¥ÑÅã¥Ü¨ç¦¡ display.m ©Ò²£¥Íªºµ²ªG¡C¡]·íµM¡A³oÓ¦r¦ê¥i¯à¤£¬O«Ü²Å¦X¤@¯ë¦h¶µ¦¡ªº¼gªk¡AŪªÌ¥i¥H¦Û¦æקï display.m¡A¨Ï¨ä²£¥Íªº¦r¦ê§óº}«G¤@¨Ç¡C¡^
¥Ñ¨Ï¥ÎªÌ©Ò©w¸qªºÃþ§O¡A¨Æ¹ê¤W¬OÄÝ©ó MATLAB ¸ê®ÆÃþ§O¶¥¼hªº¤@³¡¥÷¡AMATLAB¸ê®ÆÃþ§O¶¥¼h¦p¤U¡G
¨ä¤¤ªº user classes ´N¬O¥Ñ¨Ï¥ÎªÌ©w¸qªºÃþ§O¡A¥¦Ä~©Ó¤F structure Ãþ§Oªº¬ÛÃö¯S©Ê¡C¥Ñ¤Wz¸ê®ÆÃþ§O¶¥¼h¡A§ÚÌ¥i¥HÁA¸Ñ¸ê®ÆÃþ§O¤§¶¡ªº±qÄÝÃö«Y¡C
¤@¯ë¦Ó¨¥¡A¤ä´© OOP ªºµ{¦¡»y¨¥¤j²¤³£¦³¤Uz°ò¥»¥\¯à¡G
- ¨ç¦¡¤Î¹Bºâ¤¸ªº«¸ü (Function and operator overloading)¡G®Ú¾Ú¯S©wªºÃþ§O©Îª«¥ó¡A§A¥i¥H²£¥Í¦UºØ¤èªk¡C¹ïÀ³³o¨Ç¤èªkªº¨ç¦¡¦WºÙ¥i¥H©M MATLABªº¤º«Ø¨ç¦¡¤@¼Ë¡A¦ýMATLAB·|®Ú¾Ú¿é¤J°Ñ¼Æªº¸ê®Æ«¬ºA¡A¨Ó¨M©w©I¥sþ¤@ºØ¨ç¦¡¡C
- ¸ê®Æ©M¤èªkªº«Ê¸Ë (Encapsulation of data and methods)¡G©Ò¦³ª«¥óªº©Ê½è¡A¨ÃµLªk±q¥~¬Éª½±µ¨ú±o©Îקï¡A¥²¶·¸g¥Ñ¦¹ª«¥ó©Ò´£¨Ñªº¤èªk¡A¤~¯à¨ú±o©Îק惡ª«¥óªº©Ê½è¡C³o¼Ë¥i¥H«OÃÒª«¥óªº§¹¾ã©Ê¡A¤£·|»~¾DŪ¨ú©Îקï¡C¦¹¥~¡Aª«¥óªº¤èªk¤]¥u¾A¥Î©óª«¥ó¥»¨¡A½T«O¤£·|»~¥Î¡C
- Ä~©Ó (Inheritance)¡GÃþ§O¥i¥H¦³Ä~©ÓÃö«Y¡A¨Ò¦p¡u¤H¡v¬O¤@ºØÃþ§O¡A¦Ó¡u¾Ç¥Í¡v«h¬O¡u¤H¡vªº¤lÃþ§O¡A¦]¦¹¡u¾Ç¥Í¡vÃþ§O¥i¥HÄ~©Ó¡u¤H¡vÃþ§Oªº©Ê½è©M¤èªk¡Cµ½¥ÎÄ~©Ó¡A¥iÅý§Ú̹ï¯u¹ê¥@¬Éªº´yz§ó¥[§¹µ½¡C
- »E¦X (Aggregation)¡G§ÚÌ¥i¥H¨Ï¥Î»E¦Xªº·§©À¨Ó©w¸q¬Y¨ÇÃþ§O¡A¸g¥Ñ³oºØÃþ§O©Ò²£¥Íªºª«¥ó¡A¥i¥H¥]§t¨ä¥Lª«¥ó¡C¨Ò¦p¡A¡u¾Ç¥Í¡v©Òתº¡u½Òµ{¡v¡A´N¥i¥H¥Ñ»E¦X¨Ó©w¸q¡C
¥H¤U´X¸`±N»¡©ú MATLAB ¹ï³o¨Ç OOP ¯S©Êªº¹ê§@©M½d¨Ò¡C
MATLABµ{¦¡³]p¡G¶i¶¥½g