Rank: 1525 based on 88 downloads (last 30 days) and 4 files submitted
photo

Bobby Nedelkovski

E-mail

Personal Profile:

 

Watch this Author's files

 

Files Posted by Bobby Nedelkovski View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
26 Jul 2010 Screenshot Design Pattern: Iterator (Behavioural) A MATLAB® OOP implementation of the Iterator Behavioural Design Pattern Author: Bobby Nedelkovski behavioural, design pattern, object oriented progr..., oop, iterator, uml 21 2
  • 5.0
5.0 | 1 rating
19 Jul 2010 Screenshot Data Structure: A Cell Array List Container Provides a useful 1D container for storing an ordered heterogeneous set of elements Author: Bobby Nedelkovski data structure, cell array, list, container, adt, abstract data type 22 6
  • 4.0
4.0 | 2 ratings
28 Sep 2009 Screenshot Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski clone, object oriented progr..., copy, object 18 10
  • 3.0
3.0 | 1 rating
05 Aug 2009 Screenshot Design Pattern: Singleton (Creational) A MATLAB® OOP implementation of the Singleton Creational Design Pattern Author: Bobby Nedelkovski design pattern, singleton, creational, oop, object oriented progr..., global 27 3
  • 4.33333
4.3 | 3 ratings
Comments and Ratings by Bobby Nedelkovski View all
Updated File Comments Rating
07 Jun 2010 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski

Thank you for your suggestions Barry and Holger. I recall encountering Holger's File Exchange posting some time ago and I was going to suggest this in response to Barry's feedback - this is a good workaround given the trade-offs.

11 Apr 2010 Data Structure: A Cell Array List Container Provides a useful 1D container for storing an ordered heterogeneous set of elements Author: Bobby Nedelkovski

Thank you for your feedback and suggestions Joao.

I appreciate you pointing out the bug with the add() method in class CellArrayList. The bug (infinite while-loop) occurs when capacity = numElts and remove() is called numElts consecutive times to reduce capacity to 0. Subsequently, if you call add(), the while-loop used to re-allocate memory for the list cell array container won’t exit!

I have since fixed this issue and have submitted an update which will be published on the File Exchange soon.

Your suggestions of overloading critical MATLAB system methods such as ‘subsref’ and ‘subsasgn’ for the short-term benefits of element/property replacement is dangerous. Experienced MATLAB programmers will know that natural index notation is used to index into arrays of data types e.g. array of structs or array of cell arrays or array of char arrays or in this case, array of CellArrayLists!

Incidentally, I have just uncovered another bug with reference to how I’ve implemented all my methods with respect to the creation of arrays of CellArrayLists – i.e. myList = CellArrayList(); myList(2) = CellArrayList(); – and the way in which I’ve overloaded system methods ‘isempty’, ‘length’ and ‘display’!

This just goes to show that you need to be extremely cautious when deciding to overload MATLAB system methods! However, I like the idea of having a specialised ‘replace’ method which will effectively execute the ‘remove’ method followed by the ‘add’ method. In this way, you can easily replace elements in the list yet according to OOP practice, it is still perfectly acceptable for programmers to retrieve ADT elements and simply modify properties (this is all you need to do for objects of reference behaviour) and insert them back into the list (for objects of copy behaviour).

Joao, please feel free to contribute to the development of the ‘replace’ method. I can review your code if you send it to me by email which you can find off my File Exchange profile page (just click on the hyperlink ‘Bobby Nedelkovski’ on this page).

20 Sep 2009 Design Pattern: Iterator (Behavioural) A MATLAB® OOP implementation of the Iterator Behavioural Design Pattern Author: Bobby Nedelkovski

Thank you for your feedback Kun-Chul.

To provide clarification to the comment "good implementation for the oo design principle: polymorphism!!":

The CellArrayList implementation of the List ADT provides 'polymorphism' at the element level as I've indicated in File Exchange item #25024 by stating that CellArrayList is a storage container for a *heterogeneous* set of elements.

On the other hand, polymorphism at the list object creation level can't be generally enforced since MATLAB is loosly typed. Ideally, to conform with good software engineering practice, it would be beneficial to declare an identifier using an interface/abstract class so you just need to change the instantiating class if you simply want to switch from one implementation of List to another (i.e. you cannot perform "List myList = CellArrayList();" so then you would simply need to modify this line to use another implementation "List myList = AnotherImplList();"). So in this case, polymorphism is not apparent in MATLAB OOP.

On the alternative implementation of method 'locationsOf' (i.e. "locs = find(cellfun('isclass',obj.list,class(elt)));"), I have asserted in the comments for 'locationsOf' in abstract class 'List.m' that it should return the locations of all occurances of a single element in the list; speed shouldn't be necessarily the issue here. Hence why I use a strict equality test in "locs = find(cellfun(@(c)isequal(c,elt),obj.list));" *not* simply checking the element type. For example, if I define a list of the sort "x = [1,2,{3,4;5,6},{7,8;9,10},11]" and test x.locationsOf(2), the 'isequal' implementations yields the correct result of 2. The 'isclass' implementation will yield the relative locations of elements 1,2 and 11 given their data type matches the data type of the input argument. This is then contrary to the "contractual agreement" defined in the comments for 'locationsOf' in the abstract class 'List.m'. Sure, though you are welcome to have specialised methods in your custom subclasses of the List ADT - for example, perhaps an 'isclass' operation could be be encapsulated in a method called 'classTypeLocationsOf'.

Finally, to comment on "I hope Mathworks to develop cell array vectorization for matlab oop...", the idea of this CellArrayList realisation of the List ADT and OOP in general is to hide the low-level detail in implementation of certain functionality (like performing "find(cellarray..." or even for that matter "find(listObj==obj)" as suggested) since the user of CellArrayList only needs to know how to use 'locationsOf'. So the onus is on the developer to create their own implementations of specific class methods using base MATLAB functionality; therefore OOP shouldn't be seen as a replacement for or thought of as superseding base MATLAB functionality since functions like 'cellfun' still have their place.

20 Sep 2009 Data Structure: A Cell Array List Container Provides a useful 1D container for storing an ordered heterogeneous set of elements Author: Bobby Nedelkovski

Thank you for your feedback Kun-Chul.

To provide clarification to the comment "good implementation for the oo design principle: polymorphism!!":

The CellArrayList implementation of the List ADT provides 'polymorphism' at the element level as I've indicated in File Exchange item #25024 by stating that CellArrayList is a storage container for a *heterogeneous* set of elements.

On the other hand, polymorphism at the list object creation level can't be generally enforced since MATLAB is loosly typed. Ideally, to conform with good software engineering practice, it would be beneficial to declare an identifier using an interface/abstract class so you just need to change the instantiating class if you simply want to switch from one implementation of List to another (i.e. you cannot perform "List myList = CellArrayList();" so then you would simply need to modify this line to use another implementation "List myList = AnotherImplList();"). So in this case, polymorphism is not apparent in MATLAB OOP.

On the alternative implementation of method 'locationsOf' (i.e. "locs = find(cellfun('isclass',obj.list,class(elt)));"), I have asserted in the comments for 'locationsOf' in abstract class 'List.m' that it should return the locations of all occurances of a single element in the list; speed shouldn't be necessarily the issue here. Hence why I use a strict equality test in "locs = find(cellfun(@(c)isequal(c,elt),obj.list));" *not* simply checking the element type. For example, if I define a list of the sort "x = [1,2,{3,4;5,6},{7,8;9,10},11]" and test x.locationsOf(2), the 'isequal' implementations yields the correct result of 2. The 'isclass' implementation will yield the relative locations of elements 1,2 and 11 given their data type matches the data type of the input argument. This is then contrary to the "contractual agreement" defined in the comments for 'locationsOf' in the abstract class 'List.m'. Sure, though you are welcome to have specialised methods in your custom subclasses of the List ADT - for example, perhaps an 'isclass' operation could be be encapsulated in a method called 'classTypeLocationsOf'.

Finally, to comment on "I hope Mathworks to develop cell array vectorization for matlab oop...", the idea of this CellArrayList realisation of the List ADT and OOP in general is to hide the low-level detail in implementation of certain functionality (like performing "find(cellarray..." or even for that matter "find(listObj==obj)" as suggested) since the user of CellArrayList only needs to know how to use 'locationsOf'. So the onus is on the developer to create their own implementations of specific class methods using base MATLAB functionality; therefore OOP shouldn't be seen as a replacement for or thought of as superseding base MATLAB functionality since functions like 'cellfun' still have their place.

04 Aug 2009 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski

This File Exchange item is now under review. WARNING: Neither the original method (leveraging ‘TestClass.m’ with the ‘copyobj’ method as a template for your custom class) nor using Volkmar’s suggestion (inherit the Volkmar’s proposed ‘copyobj’ method by subclassing ‘TestClass.m’) produces a truly ‘deep’ copy of a handle object. Instead, both methods yield ‘deep’ copies of public properties in the custom superclass hierarchy yet they produce ‘shallow’ copies of private and protected properties. This has to do with the depth in scope of private and protected properties to an instance…

Case: Values of private properties declared in any superclass or protected properties declared in any grandparent class or higher cannot be copied. Accessor methods for private and protected properties can be customised – for instance, getMyProperty(obj). If a private property is modified with a custom set method and since this custom method is not part of the property’s meta-data (i.e. “GetMethod = []” in its corresponding “meta.property” object), one cannot copy the value of the private property using simple assignment with Dynamic Expressions. Moreover, you cannot temporarily modify the property’s “GetMethod=getMyProperty(obj)” nor “GetAccess=Public” meta-data fields to assume necessary control to copy private properties.

I am currently investigating possibilities in producing a truly ‘deep’ copy of a handle object. Please feel free to email any suggestions to bobby.nedelkovski@mathworks.com.au.

Comments and Ratings on Bobby Nedelkovski's Files View all
Updated File Comment by Comments Rating
25 Jun 2013 Design Pattern: Singleton (Creational) A MATLAB® OOP implementation of the Singleton Creational Design Pattern Author: Bobby Nedelkovski Abel

Not thread safe as far as I can tell. Nor any documentation even addressing the issue.

16 Nov 2012 Design Pattern: Singleton (Creational) A MATLAB® OOP implementation of the Singleton Creational Design Pattern Author: Bobby Nedelkovski Ron Lu

Nice example of singleton class. Thank you!

18 Nov 2011 Design Pattern: Singleton (Creational) A MATLAB® OOP implementation of the Singleton Creational Design Pattern Author: Bobby Nedelkovski Brad Stiritz

Thank you Bobby! for your excellent implementation of this classic design pattern. I especially appreciate your extensive documentation & excellent, highly-descriptive coding style.
5-stars well-deserved. If only all MATLAB code could look like this! Highly recommended.

17 Nov 2011 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski Shaw

for a handle class contains another handle object. I would do deep copy "recursively". (the following one might face the loop situation.)

classdef B < handle
properties
a % A obj
end
methods
function this = B()
this.a = A();
end

% class A should have the SIMILAR
% clonePublic function
function newObj = clonePublic(this)
props = properties(this);
newObj = B();
for i = 1: length(props)
tmp = this.(props{i});
if(isa(tmp,'handle'))
newObj.(props{i}) = tmp.clonePublic();
else
newObj.(props{i}) = tmp ;
end
end
end
end
end

17 Nov 2011 Clone Handle Object - using MATLAB OOP How to clone an object (deep copy) which inherits reference behaviour from the 'handle' class. Author: Bobby Nedelkovski Shaw

test

Contact us