doz22551 2016-08-03 06:20
浏览 99

使用抽象类和接口类的场景

I know the concepts of Abstract Class and Interface Class. But I want real time example which explains both the concept in our design. Can anyone help with this?

  • 写回答

2条回答 默认 最新

  • duanlei2458 2016-08-03 06:32
    关注

    Here I am mentioning some point what we can do with abstract class and interface

    1. In abstract class you can define abstract methods which should be public or protected. but in Interface you can define public abstract method only.
    2. In abstract class you can define data members and constants but in interface you can define constants only.
    3. In abstract class you can define body of method and you can inherit in sub class, but in interface you can not define body of method.
    4. you can implement multiple interface in a sub class, but you can not inherit multiple abstract classes in a sub class.

    Example

    In Major Frameworks, uses interfaces for different types of data source class. If we want to make data source class for new introduced database then we must have to implement their interface in our class so it make well maintained code and methods parameters.

    评论

报告相同问题?