From: Steven Lord on 23 Apr 2010 10:08 "sravan kumar" <fourthbatch.cse(a)gmail.com> wrote in message news:hqrjsh$k4o$1(a)fred.mathworks.com... > wat is meant by > "constructor must preserve the class of the returned object". If you're writing the constructor for your class, let's say the book class, then whatever it returns must be an instance of the book class itself. You can't do something like: classdef book properties % some properties here end methods function obj = book(genre, varargin) if nargin < 1 genre = ''; end switch genre case 'comic' obj = createComicInstead(varargin); case 'textbook' obj = createTextbookInstead(varargin); otherwise % etc end end end end and have book's constructor sometimes return a comic object and sometimes a textbook object, even if both those classes are subclasses of book. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: Haar Wavelet Transform on 8x8 matrix Next: Connect a parameter name to a moving number |