.


:




:

































 

 

 

 


-




 

C++ - . - . Eiffel Smalltalk.

Window Eiffel C++:

class WINDOW

export

add_box, add_circle, clear_selections, cut_selections,

group_selections, move_selections,

redraw_all, select_item, ungroup_selections

feature

xmin, ymin, xmax, ymax: REAL;

Create (x0, y0, width, height: REAL) is body end;

add_box (x, y, width, height: REAL) is body end;

add_circle (x, y, radius: REAL) is body end;

add_to_selections (ashape: SHAPE) is body end;

clear_selections is body end;

cut_selections is body end;

group_selections: Group is body end;

move_selections (deltax, deltay: REAL) is body end;

redraw_all is body end;

select_item (x, y: REAL) is body end;

ungroup_selections is body end;

end -- class WINDOW

(feature) ( C++) , : export. Create ( C++) . .

Smalltalk : Smalltalk , . Smalltalk : (, , ) , , , , , .

Window Smalltalk :

class name Window

superclass Object

instance variables xmin, ymin, xmax, ymax: REAL

class methods

instantiating

createAt aPoint of Width: width ofHeigt: heigt

instance methods

adding shapes

addboxAt aPoint ofWidth: width ofHeigt: heigt

addCircleAt aPoint ofRadius: radius

refreshing window

redrawAll

manipulating selections

clearSelections

cutSelections

groupSelections

moveSelectionsBy: deltaPoint

selectItemAt: aPoint

ungroupSelections

private

addToSelections: aShape

Smalltalk Object, Smalltalk, Object. , , . . , private, . , . Smalltalk @, . x y ( ) aPoint, (x,y). (3,4) a Point @ :

aPoint <- 3 @ 4

Eiffel ( (entity)) . , () , (void), .. . :

w: WINDOW

w, , . Eiffel : Create; , w:

w.Create (0.0, 0.0, 8.5, 11.0)

Create , . Create; , :

class WINDOW

...

feature

Create (x0, y0, width, height: REAL) is

do

xmin:= x0; ymin:= y0;

xmax:= x0 + width; ymax:= y0 + height;

end

...

end -- class WINDOW

Create, Clone.

Eiffel ( , delete C++). Forget , . , , , , ( ), .

Smalltalk . . . new, Object ( Smalltalk Object). , ( ) :

w <- Window new

new . ( ):

w <- Window createAt: 0 @ 0 ofWidth: 8.5 ofHeight: 11.0

:

class name Window

...

class methods

createAt: aPoint ofWidth: width ofHeigt: heigt

| w |

w <- self new.

w initialize: aPoint ofWidth: width ofHeigt: heigt.

instance methods

initialize: aPoint ofWidth: width ofHeigt: heigt.

xmin <- aPoint x.

ymin <- aPoint y.

xmax <- xmin + width.

ymax <- ymin + height

, . initialize

 

Eiffel (routines). , (REAL, INTEGER, BOOLEAN, CHARACTER) , . ( Create, Clone Forget), . , , .

Eiffel , C++, '.' Eiffel '->' C++:

local

aShape: SHAPE;

dx, dy: REAL

do

...

aShape.move (dx, dy);

end

Eiffel . x y SHAPE:

move (deltax, deltay: REAL) is

-- move a shape by delta

do

x = x + deltax;

y = y + deltay

end

Eiffel Current, ( this C++ self Smalltalk). :

move (deltax, deltay: REAL) is

-- move a shape by delta

do

Current.x = Current.x + deltax;

Current.y = Current.y + deltay

end

Smalltalk ; , . , . (), ( ). . ( ) :

aShape moveDelta: aPoint

:

class name Shape

instance variables

x y

instance methods

moveDelta: aPoint

x <- x + aPoint x

y <- y + aPoint y

( Smalltalk (instance variables)).

, Smalltalk - self, ( ).

 

Eiffel inherit:

class ITEM

export

cut, move, pick, ungroup

feature

cut is deferred end;

move (deltax, deltay: REAL) is deferred end;

pick (x, y: REAL): BOOLEAN is deferred end;

ungroup () is deferred end

class SHAPE

export

cut, draw, erase, move, pick, ungroup, write

inherit ITEM

feature

* x, y: REAL;

cut is <body> end;

draw is <body> end;

erase is <body> end;

move (deltax, deltay: REAL) is <body> end;

pick (x, y: REAL): BOOLEAN is <body> end;

ungroup is <body> end;

write (acolor: COLOR) is deferred end;

end

classrBOX

export pick, write

inherit SHAPE redefine pick, write

feature

width, height: REAL;

Create (x0, y0, width0, height0:*REAL) is <body> end;

pick (x, y: REAL): BOOLEAN is <body> end;

write (acolor: COLOR) is <body> end

end

class CIRCLE

export pick, write

inherit SHAPE redefine pick, write

feature

radius: REAL;

Create (x0, y0, radius0: REAL) is <body> end;

pick (x, y: REAL): BOOLEAN is <body> end;

write (acolor: COLOR) is <body> end

end

deferred; . redefine.

Smalltalk Item, Shape, Box Circle Shape :

class name Item

superclass Object

class name Shape

superclass Item

instance variables

x

y

instance methods

cut

draw

erase

move: aPoint

ungroup

class name Box

superclass Shape

instance variables

width

height

instance methods

pick: aPoint

write: aColor

class methods

createAt: aPoint width: widthSize length: lengthSize

class name Circle

superclass Shape

instance variables

radius

instance methods

pick: aPoint

write: aColor

class methods

createAt: aPoint radius: radiusSize

. . .

Eiffel , C++. ( (generic)) ( , ). Eiffel LINKED_LIST, ITEM GROUP:

class ITEM

export

get_group

-- GROUP

set_group(GROUP), forget_group(GROUP)

feature

get_group: GROUP is

do

Result:= mygroup

end;

set_group(g:GROUP) is

do

mygroup:= g

end;

forget_group is

do

forget(mygroup)

end;

end --ITEM

class GROUP

export

add_item, remove_item, get_items

inherit ITEM

feature

items: LINKED_LIST[ITEM]; --

Create is

do

items.Create

end;

add_item(value:ITEM) is

do

items.finish;

items.insert_right(value);

value.set_group(Current)

end;

remove_item(value:ITEM) is

do

items.search(value,l);

items.delete;

value.forget_group

end;

get_items(number:INTEGER):ITEM is

do

Result:= items

end;

end --GROUP

Eiffel . GROUP set_group forget_group ITEM. , ITEM GROUP.

forget Eiffel ; , , , .

Smalltalk . , (Item) , (Group), Set:

class name Item

superclass Object

class name Shape

superclass Item

instance variables

group

instance methods

cut

draw

erase

move: aPoint

ungroup

--

getGroup

group

--

putGroup: aGroup

group <- aGroup

class name Group

superclass Item

instance variables

items

class methods

new

|((super new)putItems:(Set new))

instance methods

pick: aPoint

write: aColor

addItem: anItem

items add: anItem.

anItem putGroup: self

removeItem

items remove: anItem.

anItem putGroup: nil

getItems

|items copy

--

putItems: aSet

items <- aSet

, Smalltalk , , : , putGroup:, . , , , , ; , , Smalltalk , .

 





:


: 2016-10-06; !; : 325 |


:

:

- , - .
==> ...

1502 - | 1421 -


© 2015-2024 lektsii.org - -

: 0.083 .