Function referring to abstract class

1 view (last 30 days)
Hi
I'm looking to use an abstract class to represent a generic "interface" (texture) on a solar cell surface.
A "cell" object is made up of "layers" which each have a top and bottom interface:
classdef ct_layer < handle
properties
t; % layer thickness
n; % real refractive index
k; % imaj refractive index
interfaceT = ct_interface.empty % Top and Bottom interface
interfaceB = ct_interface.empty
where I want ct_interface to be the abstract class, so that I can go and make plannar interfaces or pyramidal interfaces or whatever later. I want to do it like this because not every layer needs to have an interface assigned -- it might just pick up those from adjacent layers when the cell is "assembled"
However I can't preset the "type" of interface if ct_interface is abstract, and it defaults to double[] otherwise (such that I can't add the interfaces when the time comes).
I've tried reading through all the docs without resolution, but I get the sense I'm thinking about this incorrectly.
Cheers in advance for any suggestions
Leon

Accepted Answer

Jacob Halbrooks
Jacob Halbrooks on 16 Mar 2012
Your problem description suggests to me that you might want to structure your classes according to the Strategy design pattern with a special Null object concrete strategy. I would recommend you make a package to hold your Abstract class and its concrete children.
For example, create a package folder named +CTInterfaces containing Abstract, Null, Plannar, and whatever else. Your layer class could then use Null as the default:
properties
interfaceT = CTInterfaces.Null;
interfaceB = CTInterfaces.Null;
end
  3 Comments
Jacob Halbrooks
Jacob Halbrooks on 16 Mar 2012
Think of the Null object as one that can be called just like any other CTInterfaces object, except it performs no work. That is, CTInterfaces.Null would be a class that overrides all of the necessary methods (that are defined as Abstract in CTInterfaces.Abstract), but the methods would have no code.
Leon
Leon on 17 Mar 2012
Man you guys work fast! Thanks for both the suggestions, I've gone ahead with an interfaces folder and null/empty interface. Works exactly as intended (so far!).

Sign in to comment.

More Answers (1)

Daniel Shub
Daniel Shub on 16 Mar 2012
I think the key piece is:
not every layer needs to have an interface assigned -- it might just pick up those from adjacent layers when the cell is "assembled"
I think you need to define a concrete class of ct_interface_none which is a subclass of the abstract ct_interface. The ct_interface_none class would then take care of picking up the information from the adjacent layers and deal gracefully with being in isolation..

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!