1
我想將我在java中的抽象類轉換爲swift,我不知道我做了什麼是正確的。我需要建議。在Swift 2.0中的抽象類
的實際代碼
public abstract class ProtocolLayer
{
private ProtocolLayer mUpperProtocolLayer;
private ProtocolLayer mLowerProtocolLayer;
protected byte mVersion;
public ProtocolLayer ()
{
mUpperProtocolLayer = null;
mLowerProtocolLayer = null;
mVersion = 0;
}
/**
* Sets the upper layer of the protocol used to pass the eventual message decoded at this level. Set <i>null</i> for the highest layer.
* @param pProtocolLayer upper protocol layer to set
* @see ProtocolLayer#getUpperProtocolLayer()
*/
public void setUpperProtocolLayer (ProtocolLayer pProtocolLayer)
{
mUpperProtocolLayer = pProtocolLayer;
}
/**
* Gets the upper layer of the protocol used to pass the eventual message decoded at this level.
* @return pProtocolLayer return the upper protocol layer set
* @see ProtocolLayer#setUpperProtocolLayer(ProtocolLayer)
*/
public ProtocolLayer getUpperProtocolLayer ()
{
return mUpperProtocolLayer;
}
/**
* Sets the lower layer of the protocol used to pass the eventual message encoded at this level. Set <i>null</i> for the lowest layer.
* @param pProtocolLayer lower protocol layer to set
* @see ProtocolLayer#getLowerProtocolLayer()
*/
public void setLowerProtocolLayer (ProtocolLayer pProtocolLayer)
{
mLowerProtocolLayer = pProtocolLayer;
}
/**
* Gets the lower layer of the protocol used to pass the eventual message encoded at this level.
* @return return the lower protocol layer set
* @see ProtocolLayer#setLowerProtocolLayer(ProtocolLayer)
*/
public ProtocolLayer getLowerProtocolLayer ()
{
return mLowerProtocolLayer;
}
/**
* Gets the protocol layer version of the message received
* @return version of the protocol
*/
public byte getVersion()
{
return mVersion;
}
/**
* Method to decode the received message
* @param pDataReceived buffer containing data related to this protocol layer
* @return message received
* @see ProtocolLayer#transmitt()
*/
public abstract Object receive (byte[] pDataReceived);
/**
* Method to encode and so transmit a message
* @return message encoded
* @see ProtocolLayer#receive(byte[])
*/
public abstract byte[] transmitt ();
}
我確實在迅速
protocol ProtocolLayerProtocol: class {
}
public class ProtocolLayer {
var mUpperProtocolLayer : ProtocolLayer!
var mLowerProtocolLayer : ProtocolLayer!
var mVersion : UInt8!
/**
* Sets the upper layer of the protocol used to pass the eventual message decoded at this level. Set <i>null</i> for the highest layer.
* @param pProtocolLayer upper protocol layer to set
* @see ProtocolLayer#getUpperProtocolLayer()
*/
func setUpperProtocolLayer(pProtocolLayer: ProtocolLayer!) {
self.mUpperProtocolLayer = pProtocolLayer
}
/**
* Gets the upper layer of the protocol used to pass the eventual message decoded at this level.
* @return pProtocolLayer return the upper protocol layer set
* @see ProtocolLayer#setUpperProtocolLayer(ProtocolLayer)
*/
func getUpperProtocolLayer() -> ProtocolLayer? {
return self.mUpperProtocolLayer
}
/**
* Sets the lower layer of the protocol used to pass the eventual message encoded at this level. Set <i>null</i> for the lowest layer.
* @param pProtocolLayer lower protocol layer to set
* @see ProtocolLayer#getLowerProtocolLayer()
*/
func setLowerProtocolLayer(pProtocolLayer : ProtocolLayer!) {
mLowerProtocolLayer = pProtocolLayer
}
/**
* Gets the lower layer of the protocol used to pass the eventual message encoded at this level.
* @return return the lower protocol layer set
* @see ProtocolLayer#setLowerProtocolLayer(ProtocolLayer)
*/
func getLowerProtocolLayer() -> ProtocolLayer {
return mLowerProtocolLayer
}
/**
* Gets the protocol layer version of the message received
* @return version of the protocol
*/
func getVersion() -> UInt8 {
return mVersion
}
/**
* Method to decode the received message
* @param pDataReceived buffer containing data related to this protocol layer
* @return message received
* @see ProtocolLayer#transmitt()
*/
func receive (pDataReceived : [UInt8]) -> AnyObject!{
return nil;
}
/**
* Method to encode and so transmit a message
* @return message encoded
* @see ProtocolLayer#receive(byte[])
*/
func transmitt (){}
}
你能幫助的時刻是什麼?我堅持這個類。感謝所有幫助