����� ����!�������"��#$����%� ��������������� n &���������������������������������� �������������������������� '�����'"�����������'������������������� ���!"�� ������������������ (������!�� �������������������'�����'"� n )�����!�������'��������� ������!�� n /��!��������"��������������������������������� �������������������� ������������������!"����������'��#"��� n /���������������0!����������������!"��'"�� �������!���������������������%�������� ���!"���������������"������������������������ �!���#"���!#��%�����������������*+� ,-�$����� ���"��������������"�����!"� n )&�!�""�������������������#�!������ n ��������� ������������#��!���������%���������� n /�����'����"���"��������� ���������������!"��*+� ,.����� n -������������������������'�!����������#"����'��������� ��'"�������������������'�!��������������#"����'���� ���""��1��'"�� �������������� type intSet is n �����������1��'"���������'���������������� n double sqrt (int) intSet create (); ����������������!"�������� n ����#����'"�������� insert (intSet,int); delete (intSet,int); !�����#��������� n /"�������� bool member(intSet,int); �������2����������� int size (intSet); n -������'������������ �������2������� �� end intSet; n �����������������'�!������#"����������� ������ 6 �"�������1��'"���������� n �"��������'����������������������� n �����"���������� �� �#��������� ����2�������������� n ������'"������������������������������#"�� 6 ������'����������������� �������3��0!������ '���� �"������������������� ��"����"������4 n �"���������������'������������ 6 ���������������������!�� n 5����"���"�%�"��1��'"�2� �����������"����� �����!��� 1
��������� Client A Client B Client C Client D Public & n /��������������������'���� Invokes Interface Stable n ���� ������!�� ������������������'�������������� �#�!�������1'�������!������� interface : signature and specification n ���� �'����������� ����'�������������'������������ ������������������"�����������������!"� Realizes Interface n 7����������"�2�����������!����������� '�����������"���!�������������'������������ Private & implementation ���������!��"�"���!��� Changeable n (!����!�����������"���������'����������� �1��'"� -������8�%�" n double sqrt (int n double sqrt (int x) n �������������������������������'�����'"�2� x) { { �������������'�����'"� a legitimate return 3.14159; n 9#%��!�"�2��������#�����"�������������� different } implementation ��������#������������������ } n bool member (intSet s,int i) { return IsOdd(i) ������������������ } �������������������� �������������������� /�����'������������ -������� ���"������#�������� n �� ��)����+����������'�����"�������������� n &��1�#����������������'��%���%� ��'������������"�������� n �������������������������&��1 �����������"� n (!����!���������������!"������������������ �����#�����������������1���������������� ��"������ n ��������#�����������: n (��#"����"��������'�������������������2���!����� n ����'��#"����������#���!���������� �����������#�!��������������������������������� ��'�����������������1'���� �����"���"������'�������""������"� n ���������"2���!��������#!�"���������������� n ����&�.�2�����-;�/�����7�-���"� ����%�� �������%�"��������'������""�������� �"�������������"���'��#"��� n 9������1��'"��: 2
Recommend
More recommend