Function referring to abstract class
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Jacob Halbrooks
2012-3-16
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 个评论
Jacob Halbrooks
2012-3-16
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.
更多回答(1 个)
Daniel Shub
2012-3-16
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..
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classification Trees 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!