Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.

Similar presentations


Presentation on theme: "Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features."— Presentation transcript:

1 Classes and objects Practice 2

2 Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features of the classifier can be behavioural, structural or connection.  Class is a classifier, which describes some the concept of the modeled area.

3 Basic terms  Interface is a special type of classifier that defines a way to interact with an instance of a class which implements this interface. The interface is typically involves operations, but sometimes it may include properties (attributes).  An instance of the class is an element of the model with descriptions, possibly incomplete, of the object, which has features of some definite class.

4 Task 1  The interface of accessing to the collection of the elements “Collection” summarizes the interface of working with lists “List”. An abstract class “BaseCollection” implements the interface “Collection”, an abstract class “BaseList” is a descendant of “BaseCollection” and implements an interface “List”, leaving the operation for storage of data to child classes.  Using the inheritance, add to the model a class “ArrayList” which implements the operations with lists by using an array.  Let the interface “List” contains an operation “get” for receiving the item of a list with a given position “k”. Specify in which classes this operation should be declared in order to model being consistent. Explain your answer.  Let the interface “Collection” contains the operation “add” for adding an element “obj”. Specify in which classes the behavior implementing the operation “add” may be present in namespace. Explain your answer.

5 Task 2  Class “Collections” contains public static operation “addAl”l with the returning value of a type “Boolean”. The first parameter of operation is called “coll” and has a type “Collection”, the second parameter is called “elements”, and has a type “Object” and the multiplicity greater than zero.  Add in a class “Collections” a static attribute “empty” of the type “collection”, intended only for reading.  Add in the class a line of conduct, which implements the operation “addAll”.

6 Task 3  The picture shows the pattern interfaces “Map” and “Entry”. “Map” allows to get the value of the type V by the key of the type K. Interface “Entry” is a pair of values.  Change the model so that the template “Entry” use the parameters of the template “Map”.  Define the interface “Map_StringInteger”, which specifies “String” as a type of a key and “Integer” as a type of the value in the template “Map”.  How many operations are there in the interface “Map_StringInteger”? Explain your answer.

7

8 Task 4  The interface of working with the associative array “Map” contatns in its space the interface of working with an element of an array “Entry”. The implementation of the interface “Map” includes several implementations of the interface “Entry”.  Add to the model the class “HashMap” which implements an associative array using a hash table, and the class “HashEntry” which implements the interface of working with an element of that array.  Let it be defined a private operation of increasing the size “resize” in the class “HashMap”. Under what conditions this operation will be available for the class “HashEntry”?  Using templates, choose that the type of a key and the type of a value of the interface of the associative array must match the types of a key and the type of a value in the interface of working with the elements of an array.

9 Task 5  The node of a tree “Node” can have multiple child nodes of the same class “Node”.  Using the model give an example of a binary tree, consisting of seven nodes.  Build a model of a tree in which each node has form two to five child nodes.  Develop a model of a tree, in which the nodes can be of two types: node “Oden” and node “Enod”.

10 Task 6  Hard disk “Disk” contains several folders “Folder” which can contain files “File” and folders. Works “Content” are stored on a disk in multiple files.  Using associations classes, build a model of the storage of works on a disk.  Complete the model, specify that the work can be either a picture “Picture” or some music “Music”, or film “Movie”.  Can the work be stored on one disk in different files? Explain your answer.

11 Task 7  Each instance of an abstract class “Controller” is connected under the association “Sensor” with several sensors “TrainSensor” of a train. In association “Controller” plays the role of a manager “controller”. Sensor of a train participates in the association as a sensor with a private visibility.  Using qualifiers, specify that each value of the index “Index” of a type “String” corresponds to no more than one sensor in the association “Sensor”.  Specify class “controller” so that this class receives signals of the approaching of a train “TrainSpotted” and distancing of the train “TrainLeft”, also it has the shared operation of executing commands “execute” with the parameter “cmd” of a data type “Command” and returns the value of a data type “Result”.  Define a class for a digital controller “DigitalController”, clarifying the class “controller”. In a class of a digital controller there is defined an operation “executeDigital”, which overrides the operation of executing commands of the controller and returns a numeric result “DigitalResult”.  Using instances of classes, give an example of a controller with two sensors.

12 Task 8  In the file system all data is stored in the chains of clusters, recorded in the file allocation table FAT. The table contains clusters “Cluster”, the cluster is the index of the next cluster in the chain. The cluster of the directory “Folder” contains an ordered set “lists” of records “Entry” for the files and directories. Each of their records indicates the size “size”, name “name”, attributes “attrs” and the initial cluster “Cluster”.  Specify a model so that a cluster may not be the next one in the file allocation table.  Using constraints, define a data type “Byte” with a range of values from 0 to 255.  Add a new type of cluster – the cluster “Data”, containing the data of files. Operation “getData” allows you to retrieve data of this class in the form of an array with elements of type Byte.  Specify that except “Folder” and “Data” the clusters may be only spoiled “Bad” and reserve “Reserved”.  Give an example of the file allocation table with five clusters with a single directory “folder” and two files “file1” and “file2”. “File1” is located in the cluster with the number 3, “file2” - in clusters 2 and 4. The table is placed in the first cluster, it is reserved.


Download ppt "Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features."

Similar presentations


Ads by Google