C++ model - OO, OB

The C++ programming model directly supports three programming paradigms:

  1. The procedural model as programmed in C, and, of course, supported within C++. An example of this is string manipulation using character arrays and the family of str* functions defined in the Standard C library:

    char boy[] = "Danny"; 
    char *p_son; 
    
    ... 
    
    p_son = new char[ strlen( boy ) + 1 ]; 
    strcpy( p_son, boy ); 
    
    ... 
    
    if ( !strcmp( p_son, boy )) 
       take_to_disneyland( boy ); 

  2. The abstract data type (ADT) model in which users of the abstraction are provided with a set of operations (the public interface), while the implementation remains hidden. An example of this is a String class:

    String girl = "Anna"; 
    String daughter; 
    
    ... 
    
    // String::operator=(); 
    daughter = girl; 
    
    ... 
    
    // String::operator==(); 
    if ( girl == daughter ) 
       take_to_disneyland( girl ); 

  3. The object-oriented (OO) model in which a collection of related types are encapsulated through an abstract base class providing a common interface. An example of this is a Library_materials class from which actual subtypes such as Book, Video, Compact_Disc, Puppet, and Laptop are derived:

    void 
    check_in( Library_materials *pmat ) 
    { 
       if ( pmat->late() ) 
            pmat->fine(); 
       pmat->check_in(); 
       if ( Lender *plend = pmat->reserved() ) 
            pmat->notify( plend ); 
    } 

C++ supports polymorphism through class pointers and references. This style of programming is called object-oriented.
C++ also supports a concrete ADT style of programming now called object-based (OB)—nonpolymorphic data types, such as a String class.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值