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

采纳的回答

Jacob Halbrooks
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
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.
Leon
Leon 2012-3-17
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!).

请先登录,再进行评论。

更多回答(1 个)

Daniel Shub
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..

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by