240 likes | 433 Views
Programming Design Patterns. Madhu Govindaraju mgovinda@binghamton.edu. Course mechanics. Time and Place: Office Hours: TR, 2.50 PM – 4.20 PM, Office P-15, Engineering Bldg Teaching Assistant: Bedri Sendir Office Hours: TBA Meet me during office hours or by appointment
E N D
Programming Design Patterns Madhu Govindaraju mgovinda@binghamton.edu Programming Design Patterns
Course mechanics • Time and Place: • Office Hours: TR, 2.50 PM – 4.20 PM, Office P-15, Engineering Bldg • Teaching Assistant: Bedri Sendir • Office Hours: TBA • Meet me during office hours or by appointment • Course Web page: http://www.cs.binghamton.edu/~mgovinda/courses/csx42/ • Class presentations will be available for download • Link will be posted on blackboard • Discussion and participation • Class mailing list: csx42@cs.binghamton.edu • Announcements: on mailing list and/or class web page Programming Design Patterns
In class expectations • Cell phones should be turned to silent or vibrate mode during class • No Laptops can be used during class • take notes in the old-fashioned way • Exams, quizzes, assignments should use the design patterns the way it was discussed in class • even if the book has a different signature for the pattern • Slides will NOT be provided before the lecture • Take notes in class Programming Design Patterns
Course prerequisites • An interest in thorough understanding of design patterns • programming (large) projects • Proficiency in Java (and C++). • Or willingness to pick up during the course Programming Design Patterns
Grading • 70%: 2 Exams and Quizzes • 3%: Class and listserv participation • 27%: Programming Assignments, Projects, and Homeworks • All projects/labs do NOT carry the same weight Data Structures and Algorithms
Course Book • Head First Design Patterns • Authors: Eric Freeman & Elisabeth Freeman with • Kathy Sierra & Bert Bates • Publisher: O’Reilly Programming Design Patterns
Assignments, projects and exams • Many programming assignments • Some written assignments • Project discussions in class • participation is a requirement (will be graded) • Final Grade: exams, assignments, class participation • Several surprise/Pop Quizes • Grading will be on-the-curve • Moss: An automated tool for comparing code will be used. Programming Design Patterns
Outline • This course is intended to help you write real object-oriented code • Real object-oriented code should be reasonably easy to understand and be easy to modify and extend Programming Design Patterns
Access Level Modifiers • Fill the empty cells with Yes/NO Programming Design Patterns
Access Level Modifiers • Fill the empty cells with Yes/NO Programming Design Patterns
Simple Java Programming Assignment • Write Java code to swap two strings • Do not attempt to access the internals of the string class • Did you accept the two strings from the command line? • Did you perform an error-check when you read the two strings from the command line? • Did you throw/catch exceptions? • Did you actuallytest the program against the requirements? Programming Design Patterns
For interviews … • Good design, including style guidelines • Code should be robust, amenable to testing, high performance, take care of corner/boundary • Suggestion: work on old ACM programming contest problems Programming Design Patterns
Reuse • Reuse has been the cornerstone of the promotion of object-oriented programming. • Reuse is supported by object-oriented programming languages but it does not come from class libraries • Libraries DO NOT support extensibility--the easy addition of new features in new classes. • Why? Programming Design Patterns
Example Patterns • Singleton Pattern • Observer Pattern • Simple Factory Pattern Programming Design Patterns
Abstract class vs Interface • What is the difference between an Abstract Class and a Java Interface? Programming Design Patterns
Abstract class vs Interface • An interface is used to define a set of methods that a class can choose to implement • An abstract class is similar but can include(i) data fields that can then be shared by subclasses(ii) implementations of some methods that serve as default behavior when not overridden in a subclass Programming Design Patterns
Some Object Oriented Concepts • What is the difference between Exception handling in C++/Java and error handling in C? • When should the “finally” clause be used in Java? • When should a class or method be defined as “final”? • Why is Java reflection useful? Does C++ have reflection capabilities? • Should constructors always be public? • What kind of support does Java/C++ have for multi-threaded programming? Programming Design Patterns
Some Object Oriented Concepts (2) • How can a method be declared virtual in Java? C++? • What is polymorphism? • What does “Abstraction” mean? • Why is the run-time type of a reference important in method-invocation? • When is the keyword “volatile” used in Java? Programming Design Patterns
Example Design Principle • Identify the aspects of your application that vary and separate them from what stays the same • how can this be done in programming terms? • Program to an interface, not an implementation. Programming Design Patterns
Information Hiding • Information Hiding • language feature of capability that allows certain aspects of the software from being inaccessible to the users of the software (clients) • one way to achieve this is to provide an interface, which does not change • though the underlying implementation can change, but this does not affect the users who rely just on the interface • hides design decisions that are likely to change Programming Design Patterns
Encapsulation • Encapsulation • way of organizing data and methods into a structure and concealing the way it is implemented • provides the ability to validate/process the values in a method before they are applied to the data of the object • preserves integrity of the data • encapsulation defines access levels: public, protected, private • data does NOT have to be hidden • difference from Information Hiding Programming Design Patterns
Homework-1 • Write Java code in your notebook showing how Inner Classes work • Java Inner class • How many class files are generated • What is the name of the class file generated for the inner class • Java anonymous Inner class • Argument defined anonymous inner class • How can Inner class be accessed? • Can Inner classes have static members? • Can Inner classes have static methods? Programming Design Patterns
Homework-1 • When should inner classes be used in Java? • technical reason • an example • How can Inner class be accessed? • Can Inner classes have static members? • Can Inner classes have static methods? • What is the exact compilation error you get when you try to access non-static instance variables from a static nested class Programming Design Patterns
Homework-1 • Write is the difference between inner and nested class? • Can Nested classes be static? • Java Inner class • How many class files are generated • What is the name of the class file generated for the inner class • Java anonymous Inner class • Argument defined anonymous inner class Programming Design Patterns