Picking up an OOP(2) -JAVA-Interface

Basics

前段时间和Yahoo的校招说我最近在往JAVA迁移,结果人家说那你讲讲Interface好了,一脸懵逼要是早一周看到这些多好。anyway知识是自己的,讲道理Yahoo除了新闻和天气预报好像也没什么增长点的样子hhh 废话不多说,这次讲讲自己对于Interface的理解。
有些概念呢起初拿到晦涩难懂,真正理解了意思呢就觉得啊哈,再找不出更准确描述这个概念的词了,比如说这里Interface
举个栗子:

public abstract class Door{
    abstract void open();
    abstract void close();
}

public interface Alarm{
    void alarm();
}
public class AlarmDoor extends Door implement Alarm{
    @override public void open(){};
    @override public void close(){};
    @override public void alarm(){};
}

abstract class is like blueprint, while object is the one actually build those blueprint. The interface on the other hand are similar functionality shared between objects. What I mean by similar functionality is that the interface only defines methods, while never implement a default one.

This is intuitive that if we have a interface Alarm which defines like 0 to many methods, then we say a AlarmDoor can implement Alarm. While a clock can also Alarm, whereas they clearly inheritaged from different super classes.

Some thing to address briefly, specifically

  1. Note that all interface methods are public. Do not need to put public in the front.
  2. Interface method can not have default implementation.
  3. Can’t have instance variable. However can have static final.
  4. Can extends from other interface.
  5. Multiple implementation. This is extremely important. For JAVA does not support multiple inheritance for data security concern, while simplifies here. This also consist with ISP (Interface Segregation Principle). To separate different interface, make sure they don’t corrupt each other. Then implement as many as needed in specific class.
  6. A class implement certain interface, it has to override all methods in that interface
  7. interface can be a type in passing into a method. (need to see more in detail)

Callback Pattern

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 AX 2012 中,可以使用 X++ 代码实现采购单行项目的库存拣货。下面是一个示例代码,用于从采购单行项目中拣货: ``` // 获取采购单行项目 PurchLine purchLine = PurchLine::findRecId(purchLineRecId); // 获取库存管理参数 InventParameters inventParameters = InventParameters::find(); // 获取仓库管理程序集 InventDimCtrl_InventLocation inventDimCtrl_InventLocation = new InventDimCtrl_InventLocation(); // 创建库存维度 InventDim inventDim; inventDim.InventLocationId = inventDimCtrl_InventLocation.inventLocationId(purchLine.InventLocationId, purchLine.InventSiteId); inventDim.InventSiteId = purchLine.InventSiteId; // 获取库存数量 InventQty inventQty = InventQty::newInventQty(inventDim, purchLine.ItemId, inventParameters.inventInventoryOnHand); // 获取拣货数量 Real qty = inventQty.specQty(purchLine.OrderQty); // 执行拣货 InventTrans inventTrans; inventTrans.clear(); inventTrans.TransDate = systemDateGet(); inventTrans.ItemId = purchLine.ItemId; inventTrans.Qty = qty; inventTrans.InventLocationId = inventDim.InventLocationId; inventTrans.InventSiteId = inventDim.InventSiteId; inventTrans.InventTransId = inventTransId::findOrCreate(inventTrans.TransDate, inventTrans.TransType, inventTrans.Posting, inventTrans.Voucher, inventTrans.RefCompanyId, inventTrans.RefRecId, inventTrans.RefRelationId, inventTrans.RefTableId); inventTrans.InventTransId = InventTransId::findOrCreate(inventTrans.TransDate, inventTrans.TransType, inventTrans.Posting, inventTrans.Voucher, inventTrans.RefCompanyId, inventTrans.RefRecId, inventTrans.RefRelationId, inventTrans.RefTableId); inventTrans.InventTransPosting::initFromInventTrans(inventTrans, inventParameters); inventTrans.insert(); ``` 需要注意的是,上述代码中的 `purchLineRecId`、`purchLine.ItemId`、`purchLine.OrderQty`、`purchLine.InventLocationId` 和 `purchLine.InventSiteId` 都需要根据实际业务场景进行替换或设置。此外,还需要确保拣货数量 `qty` 大于 0,才能执行拣货操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值