Function referring to abstract class
2 ビュー (過去 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!