Thread Subject: Object oriented programming question

Subject: Object oriented programming question

From: Siva Mettupalayam

Date: 1 Jul, 2008 04:32:01

Message: 1 of 1

Hi,

I have the following situation:

I have an abstract handle class A

classdef A < handle
    methods(Abstract)
        ...
    end
end

and two subclasses B and C

classdef B < A
    ...
end

classdef C < A
    ...
end

I would like to read from a file, create an object of type
B or C depending on what is read, and store it in an array:

ha = [];
while not end of file
    read line
    if cond
       h = B(...);
    else
       h = C(...);
    end
    ha = [ha h];
end while

I have the following questions:
1. Is this possible, or does ha need to be a cell array?
2. IS there a way of not growing the array and preallocate?

Thank you.

Siva

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
object oriented Siva Mettupalayam 1 Jul, 2008 00:35:04
rssFeed for this Thread

Contact us at files@mathworks.com