DOC PREVIEW
TRINITY CSCI 1321 - Objects, Classes, and UML

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Objects, Classes, and UML8-31-2004Opening DiscussionI hope everyone had a nice weekend. What did we talk about last class?Have you thought about possible project ideas? Keep in mind that the design for the assignment is due next Tuesday.Let's look a bit more at the project description and that first assignment.No Surfing PleaseIn general this is rude, but right now it could be virtually fatal for you.For the next few days we are going to be moving extremely fast. The concepts will be reiterated in many future lectures, but if you don’t try to grasp them now you will put yourself behind.When I see a lack of attention on your part, I typically have much less sympathy when you need help.What is Object-Orientation?This is actually a very difficult question to answer because it is hard to get people to agree. The one term that almost everyone will agree is part of object-orientation is encapsulation.Encapsulation is the binding together of data and functionality into entities called objects. This often also includes being able to hide some data and functionality.ObjectsAn object is basically a set of data (attributes) that has certain functions associated with it. The functions (called methods, behaviors, or operations) can act on the data for that object.In many ways, an object in an object oriented program is much like an object in the real world. It has certain things that it can do (methods) and data describing a state.Objects ContinuedKeep in mind that an object represents a single entity and gives the data for that entity.For example, computer is not an object. Your computer is an object. This is a significant distinction to make. The object itself represents a single entity, not a class of entities.Calling a method of an object is often referred to as sending it a message.ClassesAs the name implies, a class represents a class of objects. In some ways, a class is a blueprint for objects of a given type. Just as a blueprint for a car is not a car, a class is not an object.What you will write in your code are classes. (Note that not all object oriented languages are class based.) You get to specify in some general way what types of object you have in your program.Classes ContinuedIn Java objects are instances of a class.When a method is called on an object it has access to all the attributes of that object.Java in not 100% object-oriented because it has primitive types that aren’t objects and aren’t instances of any class. This was done for efficiency.When talking about classes we often talk about their interface or “public interface”. This is the set of methods and attributes that are used by other objects.Classes vs. StructsClasses are similar to structs. They add a lot more though. A struct was a blueprint for a collection of data and you could make instances of it by declaring variables of that type or using malloc to get the memory.A class can have data just like a struct, but it can also have the member functions that manipulate that data.Basics of Classes in JavaAll functions in Java are methods of some class. There are no stand alone functions.Classes, attributes, and methods each have a visibility attached to them.public - can be used by anythingpackage private - can be seen by all classes in this package (this is the default)protected - can be used by subclassesprivate - can be used only by methods of that classthis and Using MembersWhen you are writing a method of a class, it has direct access to the member data and methods of that class. You don’t have to use the ‘.’ notation.To be explicit, you can use the ‘this’ keyword which implies the object that the method was invoked on.staticThe term static in the C-family languages implies something like “there is only one”. This is true in Java as well.A static member of method is associated with the class itself, not with an object/instance of that class.They can be reached or invoked without having an object of that class too.main in JavaLike C/C++, Java programs always begin in a special method named main. However, in Java main is a static method of a class (remember there are no stand alone functions). Every class can have its own main which can be very helpful for debugging.The signature of main ispublic static void main(String[] args) { }UML Class DiagramsUML stands for Unified Modeling Language. It is a formal graphic representation of software analysis and design. There are many types of UML diagrams, but we will mainly be looking at class diagrams.In this diagram classes are represented by boxes.Java also has things called interfaces that we will look at more a little later.Inside a ClassThe box for each class is divided into three regions. The top one contains the class name and possibly some modifiers.The second region has attributes of the class. Typically these are specified with a visibility modifier followed by name:type.The third region holds operations (methods). They are displayed in a similar format but arguments can follow the name.Modifier SymbolsAny of the attributes of operations can be modified with a symbol showing visibility.+ for public# for protected- for privateAttributes can also be preceded by a ‘/’ in some design tools to show that a given attribute is read only. Note that attributes aren’t always member data.Class RelationshipsIn the diagram a subclass points to the class that it inherits from with an arrow with a closed head (more on what this means in two classes).An open header arrow in UML also gives us a way to denote when two classes are associated with one another is some way. Typically this implies that one class has attributes whose type is the other class.Associations can be labeled with a name telling what type of association it is.Example: Screen has grid of BlocksDocumentation CommentsIn Java, comments that start with /** are documentation comments. These comments are used by javadoc to produce HTML documentation.These comments should go above all classes and methods. Inside the comment you start with a summary sentence then have a paragraph describing the class or method. After that can come certain “tags” that begin with @.Minute EssayDo you have any questions about assignment #1 at this point? Remember, your design is due to me next Tuesday.Over the


View Full Document

TRINITY CSCI 1321 - Objects, Classes, and UML

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Objects, Classes, and UML
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Objects, Classes, and UML and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Objects, Classes, and UML 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?